﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Data.Common;
using System.Data;
using System.IO;
using System.Collections;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Text.RegularExpressions;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace TestMySqlConnetPoll
{
    //一、 开关量类型描述

    //#define  DIGIT_PFAN  		   0		  //破封按钮             
    //#define  DIGIT_QDH			   1		  //区段红光带             
    //#define  DIGIT_XHJKF		   2		  //信号机开放信号         
    //#define  DIGIT_AN			   3		  //普通按钮	           
    //#define  DIGIT_SBGZ			   4		  //预留类型               
    //#define  DIGIT_KZTAN	       5		  //预留类型             
    //#define  DIGIT_DCFB			   7		  //道岔反位表示黄灯       
    //#define  DIGIT_DCDB		       8		  //道岔定位表示绿灯          
    //#define  DIGIT_PRIMARYPOWER    11		  //主电源                 
    //#define  DIGIT_SLAVEPOWER      12		  //副电源                 
    //#define  DIGIT_JC_ALARM        16         //挤岔红灯               
    //#define  DIGIT_RS_ALARM        17         //熔丝报警      
    //#define  DIGIT_QJD_UP_ALARM    18         //移频设备为1报警  
    //#define  DIGIT_QJD_DOWN_ALARM  19         //移频设备为0报警
    //#define  DIGIT_DCQK_UP_ALARM   20         //道岔缺口报警
    //#define  DIGIT_SXCX_UP_ALARM   21		  //错序报警     
    //#define  DIGIT_SXDX_UP_ALARM   22		  //断相报警      
    //#define  DIGIT_SCDD_ALARM      23         //电源屏输出断电  
    //#define  DIGIT_GZAN_ALARM      25         //故障通知按钮          
    //#define  DIGIT_LSXT_ALARM      26         //联锁系统报警  
    //#define  DIGIT_DS_ALARM        29         //灯丝断丝报警    
    //#define  DIGIT_HJMH_ALARM	   30         //环境明火     
    //#define  DIGIT_HJYW_ALARM	   31         //环境烟雾     
    //#define  DIGIT_HJMJ_ALARM	   32         //环境门禁      
    //#define  DIGIT_HJSJ_ALARM      33         //环境水浸      
    //#define  DIGIT_HJBP_ALARM      34         //环境玻璃破碎 
    //#define  DIGIT_SJDD_ALARM      35         //瞬间断电报警
    //#define  DIGIT_SZRJ_ALARM      72         //上总人解      
    //#define  DIGIT_ZRJ_ALARM       73         //下总人解      
    //#define  DIGIT_ZNJKTX_ALRM	   80		  //监测与其他通信接口故障报警 
    //#define  DIGIT_CJTX_ALRM	   81		  //监测内部采集通信故障报警 
    //#define  DIGIT_CTC_DOWN_ALARM  82         //CTC系统为0报警      
    //#define  DIGIT_CTC_UP_ALARM	   83         //CTC系统为1报警     
    //#define  DIGIT_JIZHOU_ALARM    88	      //计轴开关量报警         
    //#define  DIGIT_DYP_ALARM	   89		  //智能电源屏报警      
    //#define  DIGIT_FANGZAI_ALARM   90         //防灾报警      
    //#define  DIGIT_HUOZAI_ALARM    91         //火灾报警    
    //#define  DIGIT_SJ_ALARM		   92         //SJ封连报警             
    //#define  DIGIT_QT_D            128        //普通开关量			
    //#define  DIGIT_SPACE           255        //空位


    public enum AnalogCodeType      //模拟量电报码
    {
        电源屏 = 0x10,
        外电网 = 0x11,
        ups = 0x12,
        轨道电压 = 0x20,
        轨道相位角 = 0x21,
        轨道电流 = 0x22,
        高压不对称 = 0x23,
        分路残压 = 0x24,
        计轴 = 0x25,
        轨道直流电压 = 0x26,
        牵引电流干扰电压 = 0xf5,
        道岔表示电压 = 0x30,
        道岔缺口 = 0x31,
        转辙机功率 = 0x32,
        灯丝继电器电流 = 0x40,
        灯丝继电器电压 = 0x41,
        半自动闭塞电压和电流 = 0x42,
        站联电压 = 0x43,
        电码化发送电压 = 0x50,
        电码化发送电流 = 0x51,
        电码化载频 = 0x52,
        电码化低频 = 0x53,
        电码化上边频 = 0x54,
        电码化下边频 = 0x55,
        移频发送器发送电压 = 0x58,
        移频发送器发送电流 = 0x59,
        移频发送器载频 = 0x5A,
        移频发送器低频 = 0x5B,
        主轨轨入电压 = 0x5c,
        主轨轨入载频 = 0x5d,
        主轨轨入低频 = 0x5e,
        轨出1电压 = 0x5f,
        轨出1载频 = 0x60,
        轨出1低频 = 0x61,
        轨出2电压 = 0x62,
        轨出2载频 = 0x63,
        轨出2低频 = 0x64,
        移频发送电缆侧电压 = 0x65,
        移频接收电缆侧电压 = 0x66,
        轨出1上边频 = 0x67,
        轨出1下边频 = 0x68,
        移频发送电缆侧电流 = 0x69,
        道床电阻 = 0x6a,
        轨出1分路残压 = 0x6b,
        小轨轨入电压 = 0x6c,
        ZPW2000A接口信息 = 0x90,
        轨道编码 = 0x92,
        环境模拟量 = 0x70,
        空调参数 = 0x71,
        电缆绝缘 = 0x80,
        绝缘测试值 = 0x80,
        电源漏流 = 0x81,
        异物继电器端电压 = 0x91,
        区间室外监测 = 0xa0,
        None = 0xff
    }
    public enum CSM_DevType         //集中监测设备类型
    {
        电源屏 = 1,
        ups,
        外电网,
        站内轨道电路,
        区间轨道电路,
        脉冲轨道电路,
        转辙机,
        信号机,
        电码化,
        站联,
        区间监测,
        环境检测,
        计轴,
        防灾,
        半自闭,
        绝缘,
        漏流,
        残压,
        None = 0xff
    }

    public enum AlarmTypeEnum
    {
        SJ锁闭封连报警 = 0x01,
        道岔表示不一致 = 0x02,
        挤岔 = 0x03,
        列车信号非正常关闭 = 0x04,
        火灾 = 0x05,
        故障通知按钮 = 0x06,
        外电网输入电源断相_断电报警 = 0x07,
        外电网三相电源错序报警 = 0x08,
        外电网输入电源瞬间断电报警 = 0x09,
        列车信号主灯丝断丝报警 = 0x0A,
        熔丝断丝报警 = 0x0B,
        转辙机表示缺口报警 = 0x0C,
        区间设备报警 = 0x0D,
        微机监测内部采集通信故障报警 = 0x0E,
        环境监测报警 = 0x0F,
        TDCS_CTC系统报警 = 0x10,
        列控系统报警 = 0x11,
        计算机联锁系统报警 = 0x12,
        电气特性超限报警 = 0x13,
        监测与其他系统通信接口故障报警 = 0x14,
        道岔运用次数超限预警 = 0x16,
        补偿电容断线预警 = 0x17,
        ZPW2000系统报警 = 0x18,
        应答器报警 = 0x1A,
        智能电源屏报警 = 0x1B,
        防灾异物侵限报警 = 0x22,
        TSRS设备报警 = 0x26,
        RBC报警 = 0x27,
        电源屏输出断电报警 = 0x28,
        道岔无表示报警 = 0x29,
        各种设备模拟量变化趋势_突变_异常波动预警 = 0x30,
        控制台按钮操作记录 = 0x53,
        轨道长期占用报警 = 0x58,
        智能分析预警 = 0x62,
        智能分析故障诊断 = 0x64
    }

    public class ObjLK
    {
        public int No;
        public Int32 u_time;
        public byte ABflag;
        public byte ZBflag;
        public Int16 len;
        public byte[] lkAValue = new byte[1000];
        public byte[] lkBValue = new byte[1000];
    }

    #region msgGather库的结构

    public struct AnalogObj
    {
        public AnalogCodeType type;        //模拟量类型
        public int devNo;                  //模拟量序号
    }

    /// <summary>
    /// 设备库属性结构 msgGather配置的设备属性
    /// </summary>
    public struct objMsgAttriStruct
    {
        public string AttriName;    //属性名称
        public string UnitName;     //单位
        public AnalogCodeType AnalogType;      //对应的模拟量类型
    }
    /// <summary>
    /// 设备配置列表，msgGather配置的设备列表
    /// </summary>
    public class objMsgDevStruct
    {
        public string DevName;      //设备的名称
        public List<int> AnalogSet = new List<int>() ;

        public override string ToString()
        {
            return DevName;
        }
    }
    /// <summary>
    /// 设备菜单配置列表,msgGather配置的菜单项
    /// </summary>
    public struct objMsgMenuStruct
    {
        public string MenuName;      //菜单名称
        public int MenuID;           //菜单ID
        public int MenuDevType;      //菜单的设备类型
        public int MenuType;         //菜单类型
    }
    /// <summary>
    /// msgGather.ini的配置文件结构
    /// </summary>
    public class objMsgGatherStruct
    {
        public List<objMsgAttriStruct> ArrtiList = new List<objMsgAttriStruct>();
        public List<objMsgDevStruct> DevList = new List<objMsgDevStruct>();
        public List<objMsgMenuStruct> MenuList = new List<objMsgMenuStruct>();
    }
    #endregion

    /// <summary>
    /// 单路模拟量的配置结构
    /// </summary>
    [Serializable]
    public class objSingleAnalogStruct
    {
        public string AnalogName = "";               //模拟量名称
        public Int16 Flag = 0;                      //标志位
        public Int16 ADNumber = 0;                  //AD序号
        public Int16 DisplayNumber = 0;             //显示序号
        public float ADMin = 0;                     //量程下限
        public float ADMax = 0;                     //量程上限
        public float ADCoeff = 0;                   //系数
        public float UpperThreshold = 0;            //调整上限
        public float LowerThreshold = 0;            //调整下限
        public float FLUpperThreshold = 0;          //分路上限
        public Int16 FenJiNo = 0;                   //分机号
        public string UnitName = "";                 //单位
        public float YLFlag1 = 0;                   //预留
        public float YLFlag2 = 0;
        public float YLFlag3 = 0;
        public float YLFlag4 = 0;
    }
 
    /// <summary>
    /// 每种模拟量类型的配置结构
    /// </summary>
    public class objAnalogTypeStruct
    {
        public float SpanA;             //变化范围
        public float SpanB;                //变化范围
        public int AnalogNum;           //总路数
        public int StartADNo;           //开始AD序号.
        public List<objSingleAnalogStruct> AnalogList = new List<objSingleAnalogStruct>();
    }

    public struct objDS_Struct
    {
        public string DS_Name;         //灯丝名称
        public int ThroatNumber;           //咽喉号
        public int Code;               //编码
        public int FenJiNo;              //分机号
    }
    public class objXHJ_TypeStruct
    {
        public int DS_ALLNum = 0;       //总路数
        public int CJJ_Inf = 0;         //信息来源采集机
        public int BRT_Inf = 0;         //信息来源伯瑞特
        public int BRT_StartNo = 0;     //伯瑞特开始序号
        public int BRT_ALLNum = 0;      //伯瑞特总路数
        public List<objDS_Struct> ValueList = new List<objDS_Struct>();
    }

    #region 列控配置文件

    public class lkRouteInfo
    {
        public int LSNumber = 0;            //联锁进路编号
        public int LKNumber = 0;            //列控编号
        public string LKNumber_16 = "";     //列控编号16进制
        public string JLNmae = "";          //进路名称
        public int QDNumber = 0;            //该进路区段数目
        public string JLType = "";          //进路类型
        public string StartXhjName = "";    //始端信号机名称
        public string EndXhjName = "";      //终端信号机名称
        public List<string> QD_List = new List<string>(); //区段列表
    }

//    typedef struct 
//{
//    WORD   LSJinLuID;		    //联锁进路编号
//    WORD   LKBianHao;           //列控编号
//    char   LKBianHao16[50];     //列控编号16进制
//    char   JLMingCheng[50];     //进路名称
//    BYTE   QDNumber;            //该进路区段数目
//    char   JLLeiXing[50];       //进路类型
//    char   SDXHJName[50];       //始端信号机名称
//    char   ZDXHJName[50];       //终端信号机名称
//    char   QDName1[50];     //区段1名称
//    char   QDName2[50];     //区段2名称
//    char   QDName3[50];     //区段3名称
//    char   QDName4[50];     //区段4名称
//    char   QDName5[50];     //区段5名称
//    char   QDName6[50];     //区段6名称
//    char   QDName7[50];     //区段7名称
//    char   QDName8[50];     //区段8名称
//    char   QDName9[50];     //区段9名称
//    char   QDName10[50];     //区段10名称
//    char   QDName11[50];     //区段11名称
//    char   QDName12[50];     //区段12名称
//    char   QDName13[50];     //区段13名称
//    char   QDName14[50];     //区段14名称
//    char   QDName15[50];     //区段15名称
//    char   QDName16[50];     //区段16名称
//    char   QDName17[50];     //区段17名称
//    char   QDName18[50];     //区段18名称
//    char   QDName19[50];     //区段19名称
//    char   QDName20[50];     //区段20名称
	
//}LKJLStaticStructTemplate;//用于显示联锁进路信息


    public struct lkHLPZ    //列控互联信息配置
    {
        public string Name;     //列控信息名称
        public int TypeCode;        // 类型码
        public int ProtolCode;      // 协议码
    }

    public struct lkZJYJPT_PZ       //列控主机硬件平台配置
    {
        public string SehBeiTypeName;
        public string SheBeiName;       //设备名称
    }

    public struct lkSectionCode
    {
        public string SectionName;      //轨道区段名称
        public int JiGui_ID;            //所在机柜号
        public int AtJiGuiNo;           //在机柜内的序号
    }

    public class objLkInfoClass
    {
        public string CorpName;                                                     //公司名称
        public List<lkHLPZ> HL_InfoList = new List<lkHLPZ>();                //列控互联信息配置
        public List<string> ZhuJiYjpt_SendColName = new List<string>();         //列控硬件平台上送信息列名称
        public List<lkZJYJPT_PZ> ZhuJiYjpt_SheBeiList = new List<lkZJYJPT_PZ>(); //列控硬件平台设备信息列表
        public List<string> LianSuo_RouteInfo = new List<string>();          //列控与联锁接口进路信息配置
        public List<string> LianSuo_GaiFangCommandInfo = new List<string>(); //联控与联锁改方命令信息配置
        public List<string> LianSuo_GaiFangCommRetInfo = new List<string>(); //联控与联锁改方明亮回执信息配置
        public List<string> ZhangJian_GaiFangCommandInfo = new List<string>();//列控站界改方命令信息配置
        public List<string> ZhangJian_GaiFangCommRetInfo = new List<string>();//列控站界改方命令回执信息配置
        public List<string> ZhangJian_BianJieInfo = new List<string>();         //列控中心站间边界信息
        public List<string> SendToLianSuoInfo = new List<string>();             //发送给联锁的无配线站区间方向口信息
        public List<string> LinShiLimitSpeedInfo = new List<string>();          //列控中心临时限速状态
        public List<string> BTM_CodeInfo = new List<string>();                  //应答器报文编码信息
        public List<string> Section_SendColList = new List<string>();           //轨道区段编码信息  上送列信息
        public List<lkSectionCode> SectionCodeInfo = new List<lkSectionCode>(); //轨道区段编码信息

        public List<string> ZhuBan_Info = new List<string>();                   //主板
        public List<string> ZhouBian_ErrorInfo = new List<string>();            //周边故障状态
        public List<string> System_Info = new List<string>();                   //System情报区
        public List<string> PIO_Info = new List<string>();                      //PIO机笼接口
        public List<string> LEU_Info = new List<string>();                      //LEU切换单元状态
        public List<string> CTC_TSRS = new List<string>();                      //CTC/TSRS初始化
        public List<string> TCC_CAN = new List<string>();                       //TCC机柜CAN通信
        public List<string> TCC_LianSuo = new List<string>();                   //TCC与联锁通道
        public List<string> TCC_TSRS = new List<string>();                      //TCC与TSRS通道
        public List<string> TCC_CheZhan = new List<string>();                   //TCC与车站通道
        public List<string> TCC_LianSuoJiXi = new List<string>();               //TCC与联锁机系
        public List<string> TCC_TSRS_JiXi = new List<string>();                 //TCC与TSRS机系
        public List<string> TCC_CheZhanJiXi = new List<string>();               //TCC与车站机系
        public List<string> TCC_CIGS = new List<string>();                      //TCC与CIGS板
        public List<string> LEU_TongDao = new List<string>();                   //LEU通道
        public List<string> LEU_DuanKou = new List<string>();                   //LEU端口
        public List<string> QuJianSignalName = new List<string>();              //区间信号机名称
        public List<string> QuJianXianLuName = new List<string>();              //区间线路名称
        public List<string> LinZhanName = new List<string>();                  //列控邻站名称
        public List<string> PIO_QuDongName = new List<string>();                //PIO驱动继电器名称
        public List<string> PIO_CaiJiName = new List<string>();                 //PIO采集继电器名称
        public List<string> ZaiHai_Name = new List<string>();                   //灾害继电器名称
        public List<string> ZhuangTai_SectionName = new List<string>();         //状态信息轨道名称
        public List<lkRouteInfo> RouteInfo = new List<lkRouteInfo>();    //进路信息
    }
    #endregion

    public struct kglstuct_Struct
    {
        public string Name;     //名称
        public int ADNumber;    //AD号
        public int Type;        //类型
        public int ReverseFlag; //取反标志
        public int FeiJiNo;     //分机号
        public string SourceFlag;  //信息来源标记
    }

    public struct objXHJAbnormalShut_Struct     //信号非正常关闭
    {
        public string LCXhjName;            //列车信号机名称
        public int XhjNo;               //信号机绿序号
        public string FrontFirstName;       //信号机前方第一区段红名称
        public int FrontFirstCode;          //信号机前方第一区段红名称  对应码位
        public string BackFirstName;        //信号机内方第一区段红名称
        public int BackFirstCode;           //信号机内方第一区段红名称 对应码位
        public string CancelButtonName;     //信号机所在咽喉总取消按钮名称
        public int CancelCode;              //信号机所在咽喉总取消按钮名称 对应码位
        public string LockButtonName;       //信号机所在咽喉总人解按钮名称
        public int LockCode;                //信号机所在咽喉总人解按钮名称 对应码位
    }

    public struct objFLBL_Struct
    {
        public string SectionName;     //区段名称
        public byte SectionType;       //区段类型
        public byte FlblType;          //分路不良类型
        public string FlblReason;       //分路不良原因
        public int PersonID;          //设置人ID
    }

    public struct objConfigAnalog   //配置的模拟量类型
    {
        public AnalogCodeType type; //模拟量类型
        public string TypeName;     //模拟量名称
        public string IniFileName;  //模拟量所在的库名
    }

    public struct objUpAndLowValue
    {
        public float UpValue;
        public float LowValue;
        public float ADMin;
        public float ADMax;
        public float FLUpperThreshold;
    }

    public struct objDcdlqxStruct    
    {
        public int DevNo;
        public int Flag;        //=0,表示只有一种曲线，=1，表示有四种曲线
        public string DevName;
    }

    public struct objLKHostHard_Value
    {
        public string sName;
        public string Astatue;
        public string Bstatue;
    }
    public class objLKHostHardTable
    {
        public DateTime aTime;
        public DateTime bTime;
        public List<objLKHostHard_Value> RowSet = new List<objLKHostHard_Value>();
    }

    public struct objtjDev
    {
        public int devNo;
        public string DevName;
    }
        

    public static class c_LK
    {
        static public void Init_c_LK()
        {
            //InitHostHardwarePlatform();
            //InitLianSuoJieKouRouteInfo();
            InitLK_TypeNameList();
            InitHostHardwareDev();
        }
        static public List<string> HostHardwarePlatformDevList = new List<string>();    //硬件平台设备列表
        //static public DataTable HostHardwarePlatform = new DataTable("列控中心主机硬件平台");
        //static public DataTable LianSuoJieKouRouteInfo = new DataTable("列控中心与联锁接口进路信息");
        //static public DataTable LianSuoGaiFangCommandInfo = new DataTable("列控中心与联锁改方命令信息");
        //static public DataTable LianSuoGaiFangCommandRet = new DataTable("列控中心与联锁改方回执信息");
        //static public DataTable ZhanJianGaiFangCommandInfo = new DataTable("列控中心站间改方命令信息");
        //static public DataTable ZhanJianGaiFangCommandRet = new DataTable("列控中心站间改方回执信息");
        //static public DataTable ZhanJianBoundaryInfo = new DataTable("列控中心站间边界信息");
        //static public DataTable SendToLianSuoInfo = new DataTable("发送给联锁的无配线站区间方向口信息");
        //static public DataTable TemporaryLimitSpeedState = new DataTable("列控中心临时限速状态");
        //static public DataTable SectionEncodeInfo = new DataTable("轨道区段编码信息");
        //static public DataTable TransponderEncodeInfo = new DataTable("应答器报文编码信息");

        static public void InitTransponderEncodeInfo(ref DataTable dt)
        {
            DataColumn dc = null;
            //dc = dt.Columns.Add("序号", typeof(int));
            //dc.AutoIncrement = true;
            //dc.AutoIncrementSeed = 1;
            //dc.AutoIncrementStep = 1;
            //dc.AllowDBNull = false;
            for (int i = 0; i < c_Device.LK1_Config.BTM_CodeInfo.Count; i++)
            {
                string s = c_Device.LK1_Config.BTM_CodeInfo[i];
                dt.Columns.Add(s, typeof(string));
            }
        }
        static public void InitSectionEncodeInfo(ref DataTable dt)
        {
            DataColumn dc = null;
            //dc = dt.Columns.Add("序号", typeof(int));
            //dc.AllowDBNull = false;
            //dc.AutoIncrement = true;
            //dc.AutoIncrementSeed = 1;
            //dc.AutoIncrementStep = 1;
            dt.Columns.Add("轨道名称", typeof(string));
            dt.Columns.Add("所在机柜号", typeof(int));
            dt.Columns.Add("所在机柜内序号", typeof(int));
            for (int i = 0; i < c_Device.LK1_Config.Section_SendColList.Count; i++)
            {
                string s = c_Device.LK1_Config.Section_SendColList[i];
                dt.Columns.Add(s, typeof(string));
            }
            for (int i = 0; i < c_Device.LK1_Config.SectionCodeInfo.Count; i++)
            {
                DataRow dr = dt.NewRow();
                dr["轨道名称"] = c_Device.LK1_Config.SectionCodeInfo[i].SectionName;
                dr["所在机柜号"] = c_Device.LK1_Config.SectionCodeInfo[i].JiGui_ID;
                dr["所在机柜内序号"] = c_Device.LK1_Config.SectionCodeInfo[i].AtJiGuiNo;
                dt.Rows.Add(dr);
            }
        }
        static public void InitTemporaryLimitSpeedState(ref DataTable dt)
        {
            DataColumn dc = null;
            //dc = dt.Columns.Add("序号", typeof(int));
            //dc.AutoIncrement = true;
            //dc.AutoIncrementSeed = 1;
            //dc.AutoIncrementStep = 1;
            //dc.AllowDBNull = false;
            for (int i = 0; i < c_Device.LK1_Config.LinShiLimitSpeedInfo.Count; i++)
            {
                string s = c_Device.LK1_Config.LinShiLimitSpeedInfo[i];
                dt.Columns.Add(s, typeof(string));
            }
        }
        static public void InitSendToLianSuoInfo(ref DataTable dt)
        {
            DataColumn dc = null;
            //dc = dt.Columns.Add("序号", typeof(int));
            //dc.AutoIncrement = true;
            //dc.AutoIncrementSeed = 1;
            //dc.AutoIncrementStep = 1;
            //dc.AllowDBNull = false;
            for (int i = 0; i < c_Device.LK1_Config.SendToLianSuoInfo.Count; i++)
            {
                string s = c_Device.LK1_Config.SendToLianSuoInfo[i];
                dt.Columns.Add(s, typeof(string));
            }
        }
        static public void InitZhanJianBoundaryInfo(ref DataTable dt)
        {
            DataColumn dc = null;
            dc = dt.Columns.Add("序号", typeof(int));
            //dc.AutoIncrement = true;
            //dc.AutoIncrementSeed = 1;
            //dc.AutoIncrementStep = 1;
            //dc.AllowDBNull = false;
            for (int i = 0; i < c_Device.LK1_Config.ZhangJian_BianJieInfo.Count; i++)
            {
                string s = c_Device.LK1_Config.ZhangJian_BianJieInfo[i];
                dt.Columns.Add(s, typeof(string));
            }
        }
        static public void InitZhanJianGaiFangCommandRet(ref DataTable dt)
        {
            DataColumn dc = null;
            //dc = dt.Columns.Add("序号", typeof(int));
            //dc.AutoIncrement = true;
            //dc.AutoIncrementSeed = 1;
            //dc.AutoIncrementStep = 1;
            //dc.AllowDBNull = false;
            for (int i = 0; i < c_Device.LK1_Config.ZhangJian_GaiFangCommRetInfo.Count; i++)
            {
                string s = c_Device.LK1_Config.ZhangJian_GaiFangCommRetInfo[i];
                dt.Columns.Add(s, typeof(string));
            }
        }
        static public void InitZhanJianGaiFangCommandInfo(ref DataTable dt)
        {
            DataColumn dc = null;
            //dc = dt.Columns.Add("序号", typeof(int));
            //dc.AutoIncrement = true;
            //dc.AutoIncrementSeed = 1;
            //dc.AutoIncrementStep = 1;
            //dc.AllowDBNull = false;
            for (int i = 0; i < c_Device.LK1_Config.ZhangJian_GaiFangCommandInfo.Count; i++)
            {
                string s = c_Device.LK1_Config.ZhangJian_GaiFangCommandInfo[i];

                dt.Columns.Add(s, typeof(string));

            }
        }
        static public void InitLianSuoGaiFangCommandRet(ref DataTable dt)
        {
            DataColumn dc = null;
            //dc = dt.Columns.Add("序号", typeof(int));
            //dc.AutoIncrement = true;
            //dc.AutoIncrementSeed = 1;
            //dc.AutoIncrementStep = 1;
            //dc.AllowDBNull = false;
            for (int i = 0; i < c_Device.LK1_Config.LianSuo_GaiFangCommRetInfo.Count; i++)
            {
                string s = c_Device.LK1_Config.LianSuo_GaiFangCommRetInfo[i];
                dt.Columns.Add(s, typeof(string));
            }
        }
        static public void InitLianSuoGaiFangCommandInfo(ref DataTable dt)
        {
            DataColumn dc = null;
            //dc = dt.Columns.Add("序号", typeof(int));
            //dc.AutoIncrement = true;
            //dc.AutoIncrementSeed = 1;
            //dc.AutoIncrementStep = 1;
            //dc.AllowDBNull = false;
            for (int i = 0; i < c_Device.LK1_Config.LianSuo_GaiFangCommandInfo.Count; i++)
            {
                string s = c_Device.LK1_Config.LianSuo_GaiFangCommandInfo[i];
                dt.Columns.Add(s, typeof(string));
            }
        }
        static public void InitLianSuoJieKouRouteInfo(ref DataTable dt)
        {
            DataColumn dc = null;
            //dc = dt.Columns.Add("序号", typeof(int));
            //dc.AutoIncrement = true;
            //dc.AutoIncrementSeed = 1;//起始为1
            //dc.AutoIncrementStep = 1;//步长为1
            //dc.AllowDBNull = false;//
            int len = c_Device.LK1_Config.LianSuo_RouteInfo.Count;
            for (int i = 0; i < len; i++)
            {
                string s = c_Device.LK1_Config.LianSuo_RouteInfo[i];
                dc = dt.Columns.Add(s, typeof(string));
            }
        }

        static public void InitHostHardwarePlatform(ref DataTable dt)               //初始化主机硬件平台，实时值
        {
            DataColumn dc = null;
            //dc = dt.Columns.Add("序号", typeof(int));
            //dc.AutoIncrement = true;
            //dc.AutoIncrementSeed = 1;//起始为1
            //dc.AutoIncrementStep = 1;//步长为1
            //dc.AllowDBNull = false;//
            
            dt.Columns.Add(new DataColumn("设备名称", typeof(string)));
            
            dt.Columns.Add(new DataColumn("A机状态", typeof(string)));
            
            dt.Columns.Add(new DataColumn("B机状态", typeof(string)));
            DataRow dr = dt.NewRow();
            dr["设备名称"] = "时间";
            dt.Rows.Add(dr);
            int len = c_Device.LK1_Config.ZhuJiYjpt_SheBeiList.Count;
            for (int i = 0; i < len; i++)
            {
                DataRow newRow;
                newRow = dt.NewRow();
                string s = c_Device.LK1_Config.ZhuJiYjpt_SheBeiList[i].SheBeiName;
                newRow["设备名称"] = s;
                dt.Rows.Add(newRow);
            }
            dt.PrimaryKey = new DataColumn[] { dt.Columns["设备名称"] };
        }

        static public void InitTerminal_HostHardwarePlatform(ref DataTable dt)               //初始化主机硬件平台，实时值
        {
            DataColumn dc = null;
            //dc = dt.Columns.Add("序号", typeof(int));
            //dc.AutoIncrement = true;
            //dc.AutoIncrementSeed = 1;//起始为1
            //dc.AutoIncrementStep = 1;//步长为1
            //dc.AllowDBNull = false;//

            dt.Columns.Add(new DataColumn("设备名称", typeof(string)));

            dt.Columns.Add(new DataColumn("状态", typeof(string)));
            
            DataRow dr = dt.NewRow();
            dr["设备名称"] = "时间";
            dt.Rows.Add(dr);
            int len = c_Device.LK1_Config.ZhuJiYjpt_SheBeiList.Count;
            for (int i = 0; i < len; i++)
            {
                DataRow newRow;
                newRow = dt.NewRow();
                string s = c_Device.LK1_Config.ZhuJiYjpt_SheBeiList[i].SheBeiName;
                newRow["设备名称"] = s;
                dt.Rows.Add(newRow);
            }
            dt.PrimaryKey = new DataColumn[] { dt.Columns["设备名称"] };
        }
        static public void InitHostHardwareDev()    //初始化主机硬件平台,回放时用
        {
            int len = c_Device.LK1_Config.ZhuJiYjpt_SheBeiList.Count;
            for (int i = 0; i < len; i++)
            {
                string s = c_Device.LK1_Config.ZhuJiYjpt_SheBeiList[i].SheBeiName;
                HostHardwarePlatformDevList.Add(s);
            }
        }
        static public void InitStatueInfo(ref DataSet ds)
        {
            DataTable dt = new DataTable("PIO采集继电器");
            //-------------------------------------------------------表头            
            dt.Columns.Add("设备名称", typeof(string));
            dt.Columns.Add("状态",typeof(string));
            //设备列表
            for (int i = 0; i < c_Device.LK1_Config.PIO_CaiJiName.Count; i++)
            {
                DataRow dr = dt.NewRow();
                dr["设备名称"] = c_Device.LK1_Config.PIO_CaiJiName[i];
                dt.Rows.Add(dr);
            }
            ds.Tables.Add(dt);
            //--------------------------------------------------
            //dt.Clear();
            dt = new DataTable("PIO驱动继电器");
            dt.Columns.Add("设备名称", typeof(string));
            dt.Columns.Add("状态", typeof(string));
            //设备列表
            for (int i = 0; i < c_Device.LK1_Config.PIO_QuDongName.Count; i++)
            {
                DataRow dr = dt.NewRow();
                dr["设备名称"] = c_Device.LK1_Config.PIO_QuDongName[i];
                dt.Rows.Add(dr);
            }
            ds.Tables.Add(dt);
            //----------------------------
            //dt.Clear();
            dt = new DataTable("区段空闲占用状态");
            dt.Columns.Add("设备名称", typeof(string));
            dt.Columns.Add("继电器状态", typeof(string));
            dt.Columns.Add("通信状态", typeof(string));
            for (int i = 0; i < c_Device.LK1_Config.ZhuangTai_SectionName.Count; i++)
            {
                DataRow dr = dt.NewRow();
                dr["设备名称"] = c_Device.LK1_Config.ZhuangTai_SectionName[i];
                dt.Rows.Add(dr);
            }
            ds.Tables.Add(dt);
            //----------------------------------
            //dt.Clear();
            dt = new DataTable("区间线路方向");
            dt.Columns.Add("设备名称", typeof(string));
            dt.Columns.Add("方向驱动", typeof(string));
            dt.Columns.Add("方向采集", typeof(string));
            dt.Columns.Add("方向报警", typeof(string));
            for (int i = 0; i < c_Device.LK1_Config.QuJianXianLuName.Count; i++)
            {
                DataRow dr = dt.NewRow();
                dr["设备名称"] = c_Device.LK1_Config.QuJianXianLuName[i];
                dt.Rows.Add(dr);
            }
            ds.Tables.Add(dt);
            
            //-----------------------------------
            //dt.Clear();
            dt = new DataTable("站内线路方向");
            dt.Columns.Add("设备名称", typeof(string));
            dt.Columns.Add("方向驱动", typeof(string));
            dt.Columns.Add("方向采集", typeof(string));
            //for (int i = 0; i < c_Device.LK1_Config.QuJianXianLuName.Count; i++)
            //{
            //    DataRow dr = dt.NewRow();
            //    dr["设备名称"] = c_Device.LK1_Config.QuJianXianLuName[i];
            //    dt.Rows.Add(dr);
            //}
            ds.Tables.Add(dt);
            //-------------------------------------
            //dt.Clear();
            dt = new DataTable("灾害继电器");
            dt.Columns.Add("设备名称", typeof(string));
            dt.Columns.Add("状态", typeof(string));
            for (int i = 0; i < c_Device.LK1_Config.ZaiHai_Name.Count; i++)
            {
                DataRow dr = dt.NewRow();
                dr["设备名称"] = c_Device.LK1_Config.ZaiHai_Name[i];
                dt.Rows.Add(dr);
            }
            ds.Tables.Add(dt);
            //-------------------------------------
            //dt.Clear();
            dt = new DataTable("区间信号点灯状态");
            dt.Columns.Add("设备名称", typeof(string));
            dt.Columns.Add("状态", typeof(string));
            for (int i = 0; i < c_Device.LK1_Config.QuJianSignalName.Count; i++)
            {
                DataRow dr = dt.NewRow();
                dr["设备名称"] = c_Device.LK1_Config.QuJianSignalName[i];
                dt.Rows.Add(dr);
            }
            ds.Tables.Add(dt);
            //--------------------------------------
            //-------------------------------------
            //dt.Clear();
            dt = new DataTable("站内信号降级");
            dt.Columns.Add("设备名称", typeof(string));
            dt.Columns.Add("状态", typeof(string));
            //for (int i = 0; i < c_Device.LK1_Config.QuJianSignalName.Count; i++)
            //{
            //    DataRow dr = dt.NewRow();
            //    dr["设备名称"] = c_Device.LK1_Config.QuJianSignalName[i];
            //    dt.Rows.Add(dr);
            //}
            ds.Tables.Add(dt);
        }

        //static public void InitStatueInfo(ref DataTable dt)
        //{
        //    DataColumn dc = null;
        //    dc = dt.Columns.Add("序号", typeof(int));
        //    dc.AutoIncrement = true;
        //    dc.AutoIncrementSeed = 1;//起始为1
        //    dc.AutoIncrementStep = 1;//步长为1
        //    dc.AllowDBNull = false;//
        //    dt.PrimaryKey = new DataColumn[] { dt.Columns["序号"] };
        //    dt.Columns.Add("PIO采集继电器名称", typeof(string));
        //    dt.Columns.Add("PIO采集继电器状态", typeof(string));

        //    dt.Columns.Add("PIO驱动继电器名称", typeof(string));
        //    dt.Columns.Add("PIO驱动继电器状态", typeof(string));

        //    dt.Columns.Add("区段名称", typeof(string));
        //    dt.Columns.Add("区段继电器状态", typeof(string));
        //    dt.Columns.Add("区段通信状态", typeof(string));

        //    dt.Columns.Add("区间线路名称", typeof(string));
        //    dt.Columns.Add("区段继电器状态", typeof(string));
        //    dt.Columns.Add("区段通信状态", typeof(string));
        //}

        static public List<string> LK_TypeNameList = new List<string>();    //列控类型名字列表
        /// <summary>
        /// 依据列控的协议编码检测是否是A机
        /// </summary>
        /// <param name="lkProtecol"></param>
        /// <returns></returns>
        static public string CheckIsAmachine(int lkProtecol)
        {
            foreach (lkHLPZ obj in c_Device.LK1_Config.HL_InfoList)
            {
                if (lkProtecol == obj.ProtolCode)
                {
                    if (obj.Name == "A机") return "A机";
                    else if (obj.Name == "B机") return "B机";
                    break;
                }                
            }
            return "";   
        }
        static public int GetLkProtecolNo(string TypeName)
        {            
            foreach(lkHLPZ obj in c_Device.LK1_Config.HL_InfoList)
            {
                if ("列控中心主机硬件平台" == TypeName)
                {
                    if (obj.Name == "A机") return obj.ProtolCode;
                }
                else if(obj.Name == TypeName) return obj.ProtolCode;
            }
            return -1;            
        }
        static public int GetLkTypeNo(string TypeName)
        {
            foreach (lkHLPZ obj in c_Device.LK1_Config.HL_InfoList)
            {
                if ("列控中心主机硬件平台" == TypeName)
                {
                    if (obj.Name == "A机") return obj.TypeCode;
                }
                else if (obj.Name == TypeName) return obj.TypeCode;
            }
            return -1;      
        }
        static public string GetLkTypeName(int ProtolCode)
        {
            foreach (lkHLPZ obj in c_Device.LK1_Config.HL_InfoList)
            {
                if (obj.ProtolCode == ProtolCode)
                {
                    if (obj.Name == "A机" || obj.Name == "B机") return "列控中心主机硬件平台";
                    else return obj.Name;
                }
            }
            return "";            
        }
        static public void InitLK_TypeNameList()
        {
            int len = c_Device.LK1_Config.HL_InfoList.Count;
            LK_TypeNameList.Add("列控中心主机硬件平台");
            for (int i = 0; i < len; i++)
            {
                string s = c_Device.LK1_Config.HL_InfoList[i].Name;
                if (s == "A机" || s == "B机") continue;
                LK_TypeNameList.Add(s);
            }
        }
        static public string GetLkYJPTDevName(int No)
        {
            if (No >= 0 && No < c_Device.LK1_Config.ZhuJiYjpt_SheBeiList.Count)     //列控的设备列表 在配置中少一个 主备机状态
            {
                return c_Device.LK1_Config.ZhuJiYjpt_SheBeiList[No].SheBeiName;
            }
            return "";
        }

        #region 列控配置转换
        static public string GetRouteName(int RouteNum) //依据进路编号得到进路名称
        {
            if (RouteNum >= 0 && RouteNum < c_Device.LK1_Config.RouteInfo.Count)
            {
                return c_Device.LK1_Config.RouteInfo[RouteNum].JLNmae;
            }            
            return "";
        }
        static public string GetStartSignalName(int RouteNum)   //依据进路编号得到进路始端信号机名称
        {
            if (RouteNum >= 0 && RouteNum < c_Device.LK1_Config.RouteInfo.Count)
            {
                return c_Device.LK1_Config.RouteInfo[RouteNum].StartXhjName;
            }  
            return "";
        }
        static public string GetEndSignalName(int RouteNum)     //依据进路编号得到进路终端信号机名称
        {
            if (RouteNum >= 0 && RouteNum < c_Device.LK1_Config.RouteInfo.Count)
            {
                return c_Device.LK1_Config.RouteInfo[RouteNum].EndXhjName;
            }  
            return "";
        }
        static public string GetRouteSectionName(int RouteNum, int secNo)   //依据进路编号和区段编号得到区段名称
        {
            if (RouteNum >= 0 && RouteNum < c_Device.LK1_Config.RouteInfo.Count)
            {
                if (secNo >= 0 && secNo < c_Device.LK1_Config.RouteInfo[RouteNum].QD_List.Count)
                {
                    return c_Device.LK1_Config.RouteInfo[RouteNum].QD_List[secNo];
                }
            }  
            return "";
        }
        /// <summary>
        /// 依据进路编号获得列控编号
        /// </summary>
        /// <param name="RouteNum"></param>
        /// <returns></returns>
        static public int GetLkCodeName(int RouteNum)    //
        {
            if (RouteNum >= 0 && RouteNum < c_Device.LK1_Config.RouteInfo.Count)
            {
                return c_Device.LK1_Config.RouteInfo[RouteNum].LKNumber;
            }  
            return -1;
        }
        /// <summary>
        /// 得到轨道区段低频值
        /// </summary>
        /// <param name="Code"></param>
        /// <returns></returns>
        static public string GetGDQD_DPvalue(int Code)
        {
            string s = "";
            if (Code == 0x03) s = "29.0Hz";
            else if (Code == 0x05) s = "27.9Hz";
            else if (Code == 0x09) s = "26.8Hz";
            else if (Code == 0x11) s = "25.7Hz";
            else if (Code == 0x21) s = "24.6Hz";
            else if (Code == 0x06) s = "23.5Hz";
            else if (Code == 0x0a) s = "22.4Hz";
            else if (Code == 0x12) s = "21.3Hz";
            else if (Code == 0x22) s = "20.2Hz";
            else if (Code == 0x0c) s = "19.1Hz";
            else if (Code == 0x14) s = "18.0Hz";
            else if (Code == 0x24) s = "16.9Hz";
            else if (Code == 0x18) s = "15.8Hz";
            else if (Code == 0x28) s = "14.7Hz";
            else if (Code == 0x30) s = "13.6Hz";
            else if (Code == 0x3c) s = "12.5Hz";
            else if (Code == 0x3a) s = "11.4Hz";
            else if (Code == 0x36) s = "10.3Hz";
            return s;
        }
        /// <summary>
        /// 得到轨道区段载频值
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        static public string GetGDDL_ZPvalue(int code)
        {
            string s = "";
            if (code == 0x01) s = "1701.4Hz";
            if (code == 0x03) s = "2301.4Hz";
            if (code == 0x02) s = "1698.7Hz";
            if (code == 0x0b) s = "2298.7Hz";
            if (code == 0x04) s = "2001.4Hz";
            if (code == 0x0d) s = "2601.4Hz";
            if (code == 0x08) s = "1998.7Hz";
            if (code == 0x0e) s = "2598.7Hz";
            return s;
        }

        static public string GetSignal_DispStr(int code)
        {
            if (code == 0) return "灭灯";
            if (code == 1) return "红";
            if (code == 2) return "双黄";
            if (code == 3) return "双黄闪";
            if (code == 4) return "黄";
            if (code == 5) return "绿黄";
            if (code == 6) return "绿";
            if (code == 7) return "红白";
            if (code == 8) return "白";
            if (code == 9) return "兰";
            if (code == 0x0f) return "灭灯";
            if (code == 0x0b) return "黄";
            return "灭灯";
        }
        #endregion

        #region 列控协议解析
        /// <summary>
        /// 实时信息列控协议解析
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="t"></param>        
        static public void ParseProtecol_HostHardwarePlatform(ref DataTable dt, byte[] t)
        {
            int type = t[0];
            int sontype = t[1];
            int time = t[2] + (t[3] << 8) + (t[4] << 16) + (t[5] << 24);
            int ABFlag = t[6];
            int ZBFlag = t[7];
            if (ABFlag == 0xAA)
            {
                DataRow dr = dt.Rows[0];
                dr.BeginEdit();
                dr["A机状态"] = MySql.Time_tToDateTime(time).ToString();
                dr.EndEdit();
                dr = dt.Rows.Find("主备机标志");
                dr.BeginEdit();
                if (ZBFlag == 0xAA) dr["A机状态"] = "主机";
                else if (ZBFlag == 0x55) dr["A机状态"] = "备机";
                else if (ZBFlag == 0xCC) dr["A机状态"] = "不在线";
                dr.EndEdit();
            }
            else if(ABFlag == 0x55)
            {
                DataRow dr = dt.Rows[0];
                dr.BeginEdit();
                dr["B机状态"] = MySql.Time_tToDateTime(time).ToString();
                dr.EndEdit();                
                dr = dt.Rows.Find("主备机标志");
                dr.BeginEdit();
                if (ZBFlag == 0xAA) dr["B机状态"] = "主机";
                else if (ZBFlag == 0x55) dr["B机状态"] = "备机";
                else if (ZBFlag == 0xCC) dr["B机状态"] = "不在线";
                dt.AcceptChanges();
            }
            int DevTypeNum = t[8];
            int m = 9;
            int devJS = 0;
            for (int i = 0; i < DevTypeNum; i++)
            {
                int typeCode = t[m++];    //设备类型编号
                int devNum = t[m++];        //设备数量
                for (int j = 0; j < devNum; j++)
                {                    
                    int statue = t[m++];
                    string s = "";
                    string devName = GetLkYJPTDevName(devJS+1);
                    if (devName == "") continue;
                    if (statue == 0xAA)
                    {
                        if (devName == "自系状态") s = "正常";
                        else if (devName == "Freeze标志") s = "失步";
                        else if (devName == "自系标志") s = "1系";
                        else if (devName == "Master/Slave标志") s = "主";
                        else if (devName == "他系状态") s = "正常";
                        else s = "正常";
                    }
                    else if (statue == 0x55)
                    {
                        if (devName == "自系状态") s = "异常";
                        else if (devName == "Freeze标志") s = "同步";
                        else if (devName == "自系标志") s = "2系";
                        else if (devName == "Master/Slave标志") s = "从";
                        else if (devName == "他系状态") s = "异常";
                        else s = "故障";
                    }
                    else if (statue == 0xFF)
                    {
                        s = "无效";
                    }
                    else
                    {
                        s = "";
                    }
                    if (ABFlag == 0xAA)
                    {
                        DataRow dr = dt.Rows[devJS+2];      //增加了AB机 和时间行
                        dr.BeginEdit();
                        dr["A机状态"] = s;
                        dr.EndEdit();
                    }
                    else if (ABFlag == 0x55)
                    {
                        DataRow dr = dt.Rows[devJS + 2];      //增加了AB机 和时间行
                        dr.BeginEdit();
                        dr["B机状态"] = s;
                        dr.EndEdit();
                    }
                    devJS++;    //总的设备号
                }                
            }
            ///dt.AcceptChanges();
        }
        //static public objLKHostHardTable ParseProtecol_HostHardwarePlatform(ObjLK t)
        //{
        //    objLKHostHardTable dk = new objLKHostHardTable();
        //    int typeA = t.lkAValue[0];
        //    int codetypeA = t.lkAValue[1];
        //    int typeB = t.lkAValue[0];
        //    int codetypeB = t.lkAValue[1];
        //    int aL0 = t.lkAValue[2];
        //    int aL1 = t.lkAValue[3];
        //    int aL2 = t.lkAValue[4];
        //    int aL3 = t.lkAValue[5];
        //    int atime = aL3 << 24 + aL2 << 16 + aL1 << 8 + aL0;
        //    DateTime dAtime = MySql.Time_tToDateTime(atime);
        //    int bL0 = t.lkBValue[2];
        //    int bL1 = t.lkBValue[3];
        //    int bL2 = t.lkBValue[4];
        //    int bL3 = t.lkBValue[5];
        //    int btime = bL3 << 24 + bL2 << 16 + bL1 << 8 + bL0;
        //    DateTime dBtime = MySql.Time_tToDateTime(btime);

        //    dk.aTime = dAtime;
        //    dk.bTime = dBtime;

        //    objLKHostHard_Value obj = new objLKHostHard_Value();
        //    //int ABFlagA = t.lkAValue[6];
        //    //if (ABFlagA == 0xAA) obj.Astatue = "A机";
        //    //else if (ABFlagA == 0x55) obj.Astatue = "B机";
        //    //else if (ABFlagA == 0xcc) obj.Astatue = "错误";
        //    //int ABFlagB = t.lkAValue[6];
        //    //if (ABFlagB == 0xAA) obj.Bstatue = "A机";
        //    //else if (ABFlagB == 0x55) obj.Bstatue = "B机";
        //    //else if (ABFlagB == 0xcc) obj.Bstatue = "错误";
        //    //dk.RowSet.Add(obj);
        //    obj.sName = HostHardwarePlatformDevList[0];     //第一个设备
        //    int ZB = t.lkAValue[7];
        //    if (ZB == 0xAA) obj.Astatue = "主机";
        //    else if (ZB == 0x55) obj.Astatue = "备机";
        //    else if (ZB == 0xcc) obj.Astatue = "不在线";
        //    ZB = t.lkBValue[7];
        //    if (ZB == 0xAA) obj.Bstatue = "主机";
        //    else if (ZB == 0x55) obj.Bstatue = "备机";
        //    else if (ZB == 0xcc) obj.Bstatue = "不在线";
        //    dk.RowSet.Add(obj);
        //    int atypeNum = t.lkAValue[8];
        //    int btypeNum = t.lkBValue[8];
        //    if (atypeNum != btypeNum)
        //    {
        //        MessageBox.Show("列控A,B机设备数目不一致");
        //        return null;
        //    }
        //    int m = 9;
        //    for (int i = 0; i < atypeNum; i++)
        //    {
        //        int Atypecode = t.lkAValue[m];
        //        int Btypecode = t.lkBValue[m];
        //        int AdevNum = t.lkAValue[m + 1];
        //        int BdevNum = t.lkBValue[m + 1];
        //        if (Atypecode != Btypecode && AdevNum != BdevNum)
        //        {
        //            MessageBox.Show("列控A,B机设备数目不一致");
        //            return null;
        //        }
        //        int ml = m+2;
        //        for (int k = 0; k < AdevNum; k++)
        //        {
        //            obj.sName = HostHardwarePlatformDevList[k + 1];     //设备名称
        //            int Astatue = t.lkAValue[ml];
        //            int Bstatue = t.lkBValue[ml];
        //            ml++;
        //            if (Atypecode == 1)
        //            {
        //                if (Astatue == 0xAA) obj.Astatue = "正常";
        //                else if (Astatue == 0x55) obj.Astatue = "故障";
        //                else if (Astatue == 0xff) obj.Astatue = "无效";

        //                if (Bstatue == 0xAA) obj.Bstatue = "正常";
        //                else if (Bstatue == 0x55) obj.Bstatue = "故障";
        //                else if (Bstatue == 0xff) obj.Bstatue = "无效";
        //            }
        //            else if (Atypecode == 2)
        //            {
        //                if (Astatue == 0xAA) obj.Astatue = "正常";
        //                else if (Astatue == 0x55) obj.Astatue = "故障";

        //                if (Bstatue == 0xAA) obj.Bstatue = "正常";
        //                else if (Bstatue == 0x55) obj.Bstatue = "故障";
        //            }
        //            dk.RowSet.Add(obj);
        //        }
        //        m = m + ml;
        //    }
        //    return dk;
        //}

        static public void ParseProtecol_LianSuoJieKouRouteInfo(ref DataTable dt, byte[] t)
        {
            DataRow dr = dt.NewRow();
            int type = t[0];
            int sontype = t[1];
            int aL0 = t[2];
            int aL1 = t[3];
            int aL2 = t[4];
            int aL3 = t[5];
            int atime = (aL3 << 24) + (aL2 << 16) + (aL1 << 8) + aL0;
            DateTime time = MySql.Time_tToDateTime(atime);            
            int routeNum = t[6];
            int m = 7;
            for (int i = 0; i < routeNum; i++)
            {
                try
                {
                    dr["采集时间"] = time.ToString();
                    int routeNo = t[m++];
                    dr["联锁进路编号"] = routeNo.ToString();
                    dr["列控编号"] = GetLkCodeName(routeNo).ToString();
                    dr["进路名称"] = GetRouteName(routeNo);
                    dr["起始信号机"] = GetStartSignalName(routeNo);
                    dr["终端信号机"] = GetEndSignalName(routeNo);
                    int secNum = t[m++];
                    int signalStatue = t[m++];
                    if (signalStatue == 0) dr["信号机状态"] = "灭灯";
                    else if (signalStatue == 1) dr["信号机状态"] = "红";
                    else if (signalStatue == 2) dr["信号机状态"] = "双黄";
                    else if (signalStatue == 3) dr["信号机状态"] = "双黄闪";
                    else if (signalStatue == 4) dr["信号机状态"] = "黄";
                    else if (signalStatue == 5) dr["信号机状态"] = "绿黄";
                    else if (signalStatue == 7) dr["信号机状态"] = "红黄";
                    else if (signalStatue == 8) dr["信号机状态"] = "白";
                    else if (signalStatue == 9) dr["信号机状态"] = "蓝";
                    int secByte = secNum / 2;
                    if (secNum % 2 != 0) secByte++;
                    for (int k = 0; k < secByte; k++)
                    {
                        int secStatue = t[m++];
                        int s1 = secStatue & 0x03;
                        string colName = "区段" + (k * 4 + 1).ToString();
                        string SecName = GetRouteSectionName(routeNo, k * 4 + 0);
                        if (s1 == 1) dr[colName] = SecName + ":" + "锁闭";
                        if (s1 == 2) dr[colName] = SecName + ":" + "解锁";

                        int s2 = (secStatue >> 2) & 0x03;
                        colName = "区段" + (k * 4 + 2).ToString();
                        SecName = GetRouteSectionName(routeNo, k * 4 + 1);
                        if (s2 == 1) dr[colName] = SecName + ":" + "锁闭";
                        if (s2 == 2) dr[colName] = SecName + ":" + "解锁";

                        int s3 = (secStatue >> 4) & 0x03;
                        colName = "区段" + (k * 4 + 3).ToString();
                        SecName = GetRouteSectionName(routeNo, k * 4 + 2);
                        if (s3 == 1) dr[colName] = SecName + ":" + "锁闭";
                        if (s3 == 2) dr[colName] = SecName + ":" + "解锁";

                        int s4 = (secStatue >> 6) & 0x03;
                        colName = "区段" + (k * 4 + 4).ToString();
                        SecName = GetRouteSectionName(routeNo, k * 4 + 3);
                        if (s4 == 1) dr[colName] = SecName + ":" + "锁闭";
                        if (s4 == 2) dr[colName] = SecName + ":" + "解锁";
                    }
                    dt.Rows.Add(dr);
                }
                catch
                {
                    Console.WriteLine("填充联锁接口进路信息出错");
                    break;
                }
            }
        }
        static public void ParseProtecol_LianSuoJieKouRouteInfo(ref DataTable dt, List<ObjLK> value)
        {
            foreach (ObjLK t in value)
            {
                ParseProtecol_LianSuoJieKouRouteInfo(ref dt, t.lkAValue);
            }
        }

        static public void ParseProtecol_LianSuoGaiFangCommandInfo(ref DataTable dt, byte[] t)
        {
            DataRow dr = dt.NewRow();
            int type = t[0];
            int sontype = t[1];
            int aL0 = t[2];
            int aL1 = t[3];
            int aL2 = t[4];
            int aL3 = t[5];
            int atime = (aL3 << 24) + (aL2 << 16) + (aL1 << 8) + aL0;
            DateTime time = MySql.Time_tToDateTime(atime);            
            int LineNum = t[6];
            int m = 7;
            for (int i = 0; i < LineNum; i++)
            {
                dr["记录时间"] = time.ToString();
                int LineNo = t[m++];
                dr["线路序号"] = LineNo.ToString();
                int FQJFSJ = t[m++];
                int FSJ = FQJFSJ & 0x0f;
                dr["FSJ"] = FSJ.ToString();
                int FQJ = (FQJFSJ >> 4) & 0x0f;
                dr["FQJ"] = FQJ.ToString();
                int FFAJJFAF = t[m++];
                int JFAJ = FFAJJFAF & 0X0F;
                dr["FFAJ"] = JFAJ.ToString();
                int FFAJ = (FFAJJFAF >> 4) & 0x0f;
                dr["FFAJ"] = FFAJ.ToString();
                dt.Rows.Add(dr);
            }            
        }
        static public void ParseProtecol_LianSuoGaiFangCommandInfo(ref DataTable dt, List<ObjLK> value)
        {
            foreach (ObjLK t in value)
            {
                ParseProtecol_LianSuoGaiFangCommandInfo(ref dt, t.lkAValue.ToArray());
            }
        }

        static public void ParseProtecol_LianSuoGaiFangCommandRet(ref DataTable dt, byte[] t)
        {
            DataRow dr = dt.NewRow();
            int type = t[0];
            int sontype = t[1];
            int aL0 = t[2];
            int aL1 = t[3];
            int aL2 = t[4];
            int aL3 = t[5];
            int atime = (aL3 << 24) + (aL2 << 16) + (aL1 << 8) + aL0;
            DateTime time = MySql.Time_tToDateTime(atime);            
            int LineNum = t[6];
            int m = 7;
            for (int i = 0; i < LineNum; i++)
            {
                dr["记录时间"] = time.ToString();
                int LineNo = t[m++];
                dr["线路序号"] = LineNo.ToString();
                int t1 = t[m++];
                int YFJ = t1 & 0x0f;
                dr["YFJ"] = YFJ.ToString();
                int secStatue = (t1 >> 4) & 0x03;
                if (secStatue == 2) dr["发车口区间占用状态"] = "空闲";
                else dr["发车口区间占用状态"] = "占用";
                int JQJ = (t1 >> 6) & 0X03;
                if (JQJ == 1) dr["JQJ"] = "落下";
                else if (JQJ == 2) dr["JQJ"] = "吸起";

                int t2 = t[m++];
                int FJ = t2 & 0X0F;
                dr["FJ"] = FJ;
                int FZBLBSD = (t2 >> 4) & 0x0f;
                if (FZBLBSD == 0) dr["辅助办理表示灯"] = "灭灯";
                else if (FZBLBSD == 3) dr["辅助办理表示灯"] = "闪灯";
                else if (FZBLBSD == 12) dr["辅助办理表示灯"] = "稳灯";
                dt.Rows.Add(dr);
            }            
        }
        static public void ParseProtecol_LianSuoGaiFangCommandRet(ref DataTable dt, List<ObjLK> value)
        {
            foreach (ObjLK t in value)
            {
                ParseProtecol_LianSuoGaiFangCommandRet(ref dt, t.lkAValue.ToArray());                
            }
        }

        static public void ParseProtecol_ZhanJianGaiFangCommandInfo(ref DataTable dt, byte[] t)
        {
            DataRow dr = dt.NewRow();
            int type = t[0];
            int sontype = t[1];
            int aL0 = t[2];
            int aL1 = t[3];
            int aL2 = t[4];
            int aL3 = t[5];
            int atime = (aL3 << 24) + (aL2 << 16) + (aL1 << 8) + aL0;
            DateTime time = MySql.Time_tToDateTime(atime);            
            int LineNum = t[6];
            int m = 7;
            for (int i = 0; i < LineNum; i++)
            {
                dr["记录时间"] = time.ToString();
                int LineNo = t[m++];
                dr["线路编号"] = LineNo.ToString();
                int t1 = t[m++];
                int QQJZT = t1 & 0x0f;
                if (QQJZT == 0) dr["全区间状态"] = "有车";
                else if (QQJZT == 0x0f) dr["全区间状态"] = "空闲";
                else if (QQJZT == 6) dr["全区间状态"] = "仅是有区段故障而实际无车";
                int JJSB = (t1 >> 4) & 0X0F;
                if (JJSB == 6) dr["进路锁闭状态"] = "锁闭";
                else if (JJSB == 10) dr["进路锁闭状态"] = "无发车";

                int t2 = t[m++];
                int FXZT = t2 & 0X0F;
                if (FXZT == 0X0A) dr["方向状态"] = "接车";
                else if (FXZT == 0x05) dr["方向状态"] = "发车";

                int MNZT = (t2 >> 4) & 0x03;
                if (MNZT == 0) dr["命令状态"] = "不允许";
                else if (MNZT == 1) dr["命令状态"] = "请求";
                else if (MNZT == 2) dr["命令状态"] = "允许";

                int GFMN = (t2 >> 6) & 0X03;
                if (GFMN == 0) dr["改方命令"] = "无改方操作";
                else if (GFMN == 1) dr["改方命令"] = "正常改方";
                else if (GFMN == 2) dr["改方命令"] = "辅助改方";
                dt.Rows.Add(dr);
            }            
        }
        static public void ParseProtecol_ZhanJianGaiFangCommandInfo(ref DataTable dt, List<ObjLK> value)
        {
            foreach (ObjLK t in value)
            {
                ParseProtecol_ZhanJianGaiFangCommandInfo(ref dt, t.lkAValue.ToArray());
            }
        }

        static public void ParseProtecol_ZhanJianGaiFangCommandRet(ref DataTable dt, byte[] t)
        {
            DataRow dr = dt.NewRow();
            int type = t[0];
            int sontype = t[1];
            int aL0 = t[2];
            int aL1 = t[3];
            int aL2 = t[4];
            int aL3 = t[5];
            int atime = (aL3 << 24) + (aL2 << 16) + (aL1 << 8) + aL0;
            DateTime time = MySql.Time_tToDateTime(atime);
            
            int LineNum = t[6];
            int m = 7;
            for (int i = 0; i < LineNum; i++)
            {
                dr["记录时间"] = time.ToString();
                int LineNo = t[m++];
                dr["线路编号"] = LineNo.ToString();
                int t1 = t[m++];
                int QQJZT = t1 & 0x0f;
                if (QQJZT == 0) dr["全区间状态"] = "有车";
                else if (QQJZT == 0x0f) dr["全区间状态"] = "空闲";
                else if (QQJZT == 6) dr["全区间状态"] = "仅是有区段故障而实际无车";
                int JJSB = (t1 >> 4) & 0X0F;
                if (JJSB == 6) dr["进路锁闭状态"] = "锁闭";
                else if (JJSB == 10) dr["进路锁闭状态"] = "无发车";

                int t2 = t[m++];
                int FXZT = t2 & 0X0F;
                if (FXZT == 0X0A) dr["方向状态"] = "接车";
                else if (FXZT == 0x05) dr["方向状态"] = "发车";

                int MNZT = (t2 >> 4) & 0x03;
                if (MNZT == 0) dr["命令状态"] = "不允许";
                else if (MNZT == 1) dr["命令状态"] = "请求";
                else if (MNZT == 2) dr["命令状态"] = "允许";

                int GFMN = (t2 >> 6) & 0X03;
                if (GFMN == 0) dr["改方命令"] = "无改方操作";
                else if (GFMN == 1) dr["改方命令"] = "正常改方";
                else if (GFMN == 2) dr["改方命令"] = "辅助改方";
                dt.Rows.Add(dr);
            }            
        }
        static public void ParseProtecol_ZhanJianGaiFangCommandRet(ref DataTable dt, List<ObjLK> value)
        {
            foreach (ObjLK t in value)
            {
                ParseProtecol_ZhanJianGaiFangCommandRet(ref dt, t.lkAValue.ToArray());
            }
        }


        static public void ParseProtecol_ZhanJianBoundaryInfo(ref DataTable dt, byte[] t)
        {
            DataRow dr = dt.NewRow();
            int type = t[0];
            int sontype = t[1];
            int aL0 = t[2];
            int aL1 = t[3];
            int aL2 = t[4];
            int aL3 = t[5];
            int atime = (aL3 << 24) + (aL2 << 16) + (aL1 << 8) + aL0;
            DateTime time = MySql.Time_tToDateTime(atime);
            
            int LineNum = t[6];
            int m = 7;
            for (int i = 0; i < LineNum; i++)
            {
                dr["记录时间"] = time.ToString();
                dr["线路序号"] = t[m++];
                byte yl = t[m++];   //预留一个字节
                byte tmp = t[m++];
                if ((tmp >> 6) == 0) dr["边界区段预告码标识"] = "预告";
                else if ((tmp >> 6) == 3) dr["边界区段预告码标识"] = "正常";
                tmp = (byte)(tmp & 0x3f);
                dr["边界区段低频"] = GetGDQD_DPvalue(tmp);
                tmp = t[m++];
                tmp = (byte)(tmp & 0x03);
                if (tmp == 0) dr["区段1状态"] = "故障";
                else if (tmp == 1) dr["区段1状态"] = "占用";
                else if (tmp == 2) dr["区段1状态"] = "空闲";
                else if (tmp == 3) dr["区段1状态"] = "分路不良";
                m++;    //预留空间
                m++;    //预留空间
                dt.Rows.Add(dr);
            }
        }
        static public void ParseProtecol_ZhanJianBoundaryInfo(ref DataTable dt, List<ObjLK> value)
        {
            foreach (ObjLK t in value)
            {
                ParseProtecol_ZhanJianBoundaryInfo(ref dt, t.lkAValue.ToArray());
            }
        }

        static public void ParseProtecol_SendToLianSuoInfo(ref DataTable dt, byte[] t)
        {
            DataRow dr = dt.NewRow();
            int type = t[0];
            int sontype = t[1];
            int aL0 = t[2];
            int aL1 = t[3];
            int aL2 = t[4];
            int aL3 = t[5];
            int atime = (aL3 << 24) + (aL2 << 16) + (aL1 << 8) + aL0;
            DateTime time = MySql.Time_tToDateTime(atime);
            int BHsum = t[6];
            int m = 7;
            for (int i = 0; i < BHsum; i++)
            {
                dr["记录时间"] = time.ToString();
                dr["变化车站号"] = t[m++].ToString();
                dr["变化车站发车口号"] = t[m++].ToString();
                int tmp = t[m++];
                if ((tmp & 0x30) == 2) dr["发车口区间占用状态"] = "空闲";
                else dr["发车口区间占用状态"] = "占用";
                if ((tmp & 0x0f) == 5) dr["发车口YFJ信息"] = "落下";
                else if ((tmp & 0x0f) == 10) dr["发车口YFJ信息"] = "吸起";
                dt.Rows.Add(dr);
            }
        }
        static public void ParseProtecol_SendToLianSuoInfo(ref DataTable dt, List<ObjLK> value)
        {
            foreach (ObjLK obj in value)
            {
                ParseProtecol_SendToLianSuoInfo(ref dt, obj.lkAValue.ToArray());
            }
        }

        static public void ParseProtecol_TemporaryLimitSpeedState(ref DataTable dt, byte[] t)
        {
            DataRow dr = dt.NewRow();
            int type = t[0];
            int sontype = t[1];
            int aL0 = t[2];
            int aL1 = t[3];
            int aL2 = t[4];
            int aL3 = t[5];
            int atime = (aL3 << 24) + (aL2 << 16) + (aL1 << 8) + aL0;
            DateTime time = MySql.Time_tToDateTime(atime);
            int limitNum = t[6];
            int m = 7;
            for (int i = 0; i < limitNum; i++)
            {
                dr["记录时间"] = time.ToString();
                dr["限速值"] = (t[m++] * 5).ToString() + "km/h";
                byte[] kt = new byte[16];
                Array.Copy(t, m, kt, 0, 16);    //调度命令号                
                dr["限速命令号"] = System.Text.UTF8Encoding.UTF8.GetString(kt);
                m += 16;
                int tID = t[m] + (t[m + 1] << 8);
                m += 2;
                int ctcID = t[m] + (t[m + 1] << 8) + (t[m + 2] << 16) + (t[m + 3] << 24);
                dr["操作员ID"] = ctcID.ToString() + "  " + tID.ToString();
                m += 4; //限速员操作ID
                dr["限速编号(TSR_ID)"] = t[m++].ToString();
                dr["线路号"] = t[m++].ToString();
                int xlyx = t[m++];
                if (xlyx == 1) dr["限速原因"] = "施工";
                else if (xlyx == 1) dr["限速原因"] = "风雨雪";
                else if (xlyx == 1) dr["限速原因"] = "突发灾害";
                dr["起点里程系"] = t[m++].ToString();
                int lcbz = t[m] + (t[m + 1] << 8) + (t[m + 2] << 16) + (t[m + 3] << 24);
                dr["起点公里标"] = lcbz.ToString() + "米";
                m += 4;
                dr["终点里程系"] = t[m++].ToString();
                int zdbz = t[m] + (t[m + 1] << 8) + (t[m + 2] << 16) + (t[m + 3] << 24);
                dr["终点公里标"] = lcbz.ToString() + "米";
                m += 4;
                m += 2; //预留2
                dt.Rows.Add(dr);
            }
        }        
        static public void ParseProtecol_TemporaryLimitSpeedState(ref DataTable dt, List<ObjLK> value)
        {
            foreach (ObjLK t in value)
            {
                ParseProtecol_TemporaryLimitSpeedState(ref dt, t.lkAValue.ToArray());
            }
        }

        static public void ParseProtecol_SectionEncodeInfo(ref DataTable dt, byte[] t)
        {
            DataRow dr = dt.NewRow();
            int type = t[0];
            int sontype = t[1];
            int aL0 = t[2];
            int aL1 = t[3];
            int aL2 = t[4];
            int aL3 = t[5];
            int atime = (aL3 << 24) + (aL2 << 16) + (aL1 << 8) + aL0;
            DateTime time = MySql.Time_tToDateTime(atime);
            int jkNum = t[6];
            int m = 7;
            for (int i = 0; i < jkNum; i++)
            {
                int kh = t[m++];    //柜号
                int tmp = t[m++];   //主轨载频 小轨载频
                dr["主轨载频编码"] = GetGDDL_ZPvalue(tmp >> 4);
                dr["小轨载频编码"] = GetGDDL_ZPvalue(tmp & 0x0f);
                tmp = t[m++];   //主轨低频编码
                dr["主轨低频编码"] = GetGDQD_DPvalue(tmp & 0x3f);
                tmp = t[m++];
                dr["小轨低频编码"] = GetGDQD_DPvalue(tmp & 0x3f);
                //dt.Rows.Add(dr);
            }
        }
        static public void ParseProtecol_SectionEncodeInfo(ref DataTable dt, List<ObjLK> value)
        {
            //不需要此函数，按照硬件平台方案进行
        }

        static public void ParaseProtecol_TransponderEncodeInfo(ref DataTable dt, byte[] t)
        {
            DataRow dr = dt.NewRow();
            int type = t[0];
            int sontype = t[1];
            int aL0 = t[2];
            int aL1 = t[3];
            int aL2 = t[4];
            int aL3 = t[5];
            int atime = (aL3 << 24) + (aL2 << 16) + (aL1 << 8) + aL0;
            DateTime time = MySql.Time_tToDateTime(atime);
            dr["记录时间"] = time.ToString();
            dr["TU(通信盘)编号"] = t[6].ToString();
            dr["TU-CPU号"] = t[7].ToString();
            dr["LEU编号"] = t[8].ToString();
            dr["LEU-CPU编号"] = t[9].ToString();
            dr["应答器端口号"] = t[10].ToString();
            byte[] bw = new byte[148 - 12];
            Array.Copy(t, 11, bw, 0, 136);
            string s = "";
            for (int i = 0; i < 136; i++)
            {
                s += bw[i].ToString("X2");
                s += " ";
            }
            dr["报文数据内容"] = s;
            dt.Rows.Add(dr);
        }
        static public void ParaseProtecol_TransponderEncodeInfo(ref DataTable dt, List<ObjLK> value)
        {
            foreach (ObjLK t in value)
            {
                ParaseProtecol_TransponderEncodeInfo(ref dt, t.lkAValue.ToArray());
            }
        }

        static public void ParaseProtecol_AllStatueInfo(ref DataSet ds, byte[] t)
        {
            int type = t[0];
            int sontype = t[1];
            int aL0 = t[2];
            int aL1 = t[3];
            int aL2 = t[4];
            int aL3 = t[5];
            int atime = (aL3 << 24) + (aL2 << 16) + (aL1 << 8) + aL0;
            int SBTypeNum = t[6];   //设备类型数量
            int m = 7;
            for (int i = 0; i < SBTypeNum; i++)
            {
                int SBtypeCode = t[m++];
                DataTable dt;
                if (SBtypeCode == 0x0a)
                { 
                    dt = ds.Tables["PIO采集继电器"];                    
                    int SBnum = t[m++];     //设备数量
                    for (int k = 0; k < SBnum;)
                    {
                        byte st = t[m++];       //设备状态
                        for (int y = 0; y < 8; y++)
                        {
                            DataRow dr = dt.NewRow();
                            if (((st >> y) & 0x01) == 0) dr["状态"] = "↓";
                            else dr["状态"] = "↑";
                            dt.Rows.Add(dr);
                        }
                        k += 8; //一个字节8个设备，8个状态
                    }
                }
                else if (SBtypeCode == 0x0b)
                {
                    dt = ds.Tables["PIO驱动继电器"];                    
                    int SBnum = t[m++];     //设备数量
                    for (int k = 0; k < SBnum; )
                    {
                        byte st = t[m++];       //设备状态
                        for (int y = 0; y < 8; y++)
                        {
                            DataRow dr = dt.NewRow();
                            if (((st >> y) & 0x01) == 0) dr["状态"] = "↓";
                            else dr["状态"] = "↑";
                            dt.Rows.Add(dr);
                        }
                        k += 8; //一个字节8个设备，8个状态
                    }
                }
                else if (SBtypeCode == 0x01)
                {
                    dt = ds.Tables["区段空闲占用状态"];                    
                    int SBnum = t[m++];     //设备数量
                    for (int k = 0; k < SBnum; )
                    {
                        DataRow dr = dt.NewRow();
                        byte st = t[m++];       //设备1-2状态
                        if ((st & 0x03) == 2) dr["继电器状态"] = "空闲";
                        else dr["继电器状态"] = "占用";
                        if (((st >> 2) & 0x03) == 2) dr["通信状态"] = "空闲";
                        else dr["通信状态"] = "占用";
                        dt.Rows.Add(dr);
                        //------
                        dr = dt.NewRow();
                        if (((st >> 4) & 0x03) == 2) dr["继电器状态"] = "空闲";
                        else dr["继电器状态"] = "占用";
                        if (((st >> 6) & 0x03) == 2) dr["通信状态"] = "空闲";
                        else dr["通信状态"] = "占用";
                        dt.Rows.Add(dr);
                        k += 2; //一个字节2个设备，4个状态
                    }
                }
                else if (SBtypeCode == 0x03)
                {
                    dt = ds.Tables["区间线路方向"];
                    int SBnum = t[m++];     //设备数量
                    for (int k = 0; k < SBnum; k++)     //一个字节表示一个设备状态
                    {
                        DataRow dr = dt.NewRow();
                        byte st = t[m++];
                        if ((st & 0x03) == 0x01) dr["方向驱动"] = "反向";
                        else dr["方向驱动"] = "正向";
                        if (((st >> 2) & 0x03) == 0x01) dr["方向采集"] = "反向";
                        else dr["方向采集"] = "正向";
                        if (((st >> 4) & 0x03) == 0x01) dr["方向报警"] = "报警";
                        else dr["方向采集"] = "正常";
                        dt.Rows.Add(dr);
                    }
                }
                else if (SBtypeCode == 0x04)
                {
                    dt = ds.Tables["站内线路方向"];                    
                    int SBnum = t[m++];     //设备数量
                    for (int k = 0; k < SBnum; k++)     //一个字节表示一个设备状态
                    {
                        DataRow dr = dt.NewRow();
                        byte st = t[m++];
                        if ((st & 0x03) == 0x01) dr["方向驱动"] = "反向";
                        else dr["方向驱动"] = "正向";
                        if (((st >> 2) & 0x03) == 0x01) dr["方向采集"] = "反向";
                        else dr["方向采集"] = "正向";
                        dt.Rows.Add(dr);
                    }
                }
                else if (SBtypeCode == 0x05)
                {
                    dt = ds.Tables["灾害继电器"];
                    int SBnum = t[m++];     //设备数量
                    for (int k = 0; k < SBnum; )     //一个字节表示4设备状态
                    {
                        int st = t[m++];
                        for (int y = 0; y < 4; y++)
                        {
                            DataRow dr = dt.NewRow();
                            if (((st>>(y*2)) & 0x03) == 0x03) dr["状态"] = "正常";
                            else dr["状态"] = "灾害";
                            dt.Rows.Add(dr);
                        }
                        k += 4;
                    }
                }
                else if (SBtypeCode == 0x1a)
                {
                    dt = ds.Tables["区间信号点灯状态"];
                    int SBnum = t[m++];     //设备数量
                    for (int k = 0; k < SBnum; )     //一个字节表示2设备状态
                    {
                        int st = t[m++];
                        DataRow dr = dt.NewRow();
                        dr["状态"] = GetSignal_DispStr(st&0x0f);
                        dt.Rows.Add(dr);
                        dr = dt.NewRow();
                        dr["状态"] = GetSignal_DispStr((st>>4)&0x0f);
                        dt.Rows.Add(dr);
                        k += 2;
                    }                    
                }
                else if (SBtypeCode == 0x1b)
                {
                    dt = ds.Tables["站内信号降级"];
                    int SBnum = t[m++];     //设备数量
                    for (int k = 0; k < SBnum; )     //一个字节表示2设备状态
                    {
                        int st = t[m++];
                        DataRow dr = dt.NewRow();
                        if ((st & 0x0f) == 0x05) dr["状态"] = "不降级";
                        else if ((st & 0x0f) == 0x0a) dr["状态"] = "降级";
                        dt.Rows.Add(dr);
                        dr = dt.NewRow();
                        if (((st>>4) & 0x0f) == 0x05) dr["状态"] = "不降级";
                        else if (((st>>4) & 0x0f) == 0x0a) dr["状态"] = "降级";
                        dt.Rows.Add(dr);
                        k += 2;
                    }           
                }
            }
        }
        #endregion

        #region 终端列控数据填充
        /// <summary>
        /// 依据协议填充，硬件平台，前提，表格已经初始化
        /// </summary>
        /// <param name="HostHardwarePlatform"></param>
        /// <param name="li"></param>
        static public void Fill_HostHardwarePlatform(ref DataTable HostHardwarePlatform, List<byte> li)
        {
            int m = 0;
            int lkProtecol = li[m++];
            int datalen = li[m] + (li[m + 1] << 8) + (li[m + 2] << 16) + (li[m + 3] << 24);
            m += 4;
            if (datalen != (li.Count + 6)) //协议编号1+长度+4+数据区长度+0xff
            {
                Console.WriteLine("终端接收列控实时错误");
                return;
            }
            if (lkProtecol == 0x01)
            {
                int allNum = li[m] + (li[m + 1] << 8);
                m += 2;
                int rtnum = 0;
                if (allNum >= (HostHardwarePlatform.Rows.Count - 1))
                {
                    rtnum = HostHardwarePlatform.Rows.Count - 1;
                }
                else rtnum = allNum;
                HostHardwarePlatform.Rows[0]["A机状态"] = DateTime.Now.ToString();
                for (int i = 1; i < (rtnum + 1); i++)
                {
                    int txtlen = li[m] + (li[m + 1] >> 8);
                    m += 2;
                    byte[] txt = new byte[txtlen];
                    Array.Copy(li.ToArray(), m, txt, 0, txtlen);
                    string s = System.Text.Encoding.Default.GetString(txt);
                    HostHardwarePlatform.Rows[0]["A机状态"] = s;
                }
            }
            else if (lkProtecol == 0x02)
            {
                int allNum = li[m] + (li[m + 1] << 8);
                m += 2;
                int rtnum = 0;
                if (allNum >= (HostHardwarePlatform.Rows.Count - 1))
                {
                    rtnum = HostHardwarePlatform.Rows.Count - 1;
                }
                else rtnum = allNum;
                HostHardwarePlatform.Rows[0]["B机状态"] = DateTime.Now.ToString();
                for (int i = 1; i < (rtnum + 1); i++)
                {
                    int txtlen = li[m] + (li[m + 1] >> 8);
                    m += 2;
                    byte[] txt = new byte[txtlen];
                    Array.Copy(li.ToArray(), m, txt, 0, txtlen);
                    string s = System.Text.Encoding.Default.GetString(txt);
                    HostHardwarePlatform.Rows[0]["B机状态"] = s;
                }
            }
        }

        static public void Fill_Protecol_0x10(ref DataTable dt, List<byte> li)
        {
            dt.Rows.Clear();    //清除以前的数据
            int m = 0;
            int lkProtecol = li[m++];
            int datalen = li[m] + (li[m + 1] << 8) + (li[m + 2] << 16) + (li[m + 3] << 24);
            m += 4;
            if (datalen != (li.Count + 6)) //协议编号1+长度+4+数据区长度+0xff
            {
                Console.WriteLine("终端接收列控实时错误");
                return;
            }
            int allNum = li[m] + (li[m + 1] << 8);
            m +=2;
            for (int i = 0; i < allNum; i++)
            {
                int tlen = li[m] + (li[m + 1] << 8);
                m += 2;
                byte[] txt = new byte[tlen];
                Array.Copy(li.ToArray(), m, txt, 0, tlen);
                string s = System.Text.Encoding.Default.GetString(txt);
                string[] sb = s.Split('@');
                int ik = 0;  //需要插入的列数
                if (sb.Length >= (dt.Columns.Count - 1)) ik = dt.Columns.Count - 1;
                else ik = sb.Length;
                DataRow dr = dt.NewRow();
                for (int x = 1; x <= ik; x++)
                {
                    dr[x] = sb[x - 1];
                }
                dt.Rows.Add(dr);
            }
        }

        static public void Fill_Protecol_0x02(ref DataTable dt, List<byte> li)
        {            
            int m = 0;
            int lkProtecol = li[m++];
            int datalen = li[m] + (li[m + 1] << 8) + (li[m + 2] << 16) + (li[m + 3] << 24);
            m += 4;
            if (datalen != (li.Count + 6)) //协议编号1+长度+4+数据区长度+0xff
            {
                Console.WriteLine("终端接收列控实时错误");
                return;
            }
            int allNum = li[m] + (li[m + 1] << 8);
            m += 2;
            int rtnum = 0;
            if (allNum >= (dt.Rows.Count))
            {
                rtnum = dt.Rows.Count;
            }
            else rtnum = allNum;
            for (int i = 0; i < (rtnum); i++)
            {
                int txtlen = li[m] + (li[m + 1] >> 8);
                m += 2;
                byte[] txt = new byte[txtlen];
                Array.Copy(li.ToArray(), m, txt, 0, txtlen);
                string s = System.Text.Encoding.Default.GetString(txt);
                string[] sb = s.Split('@');                
                if (sb.Length != 4)
                {
                    Console.WriteLine("终端接收列控实时错误");
                    return;
                }                
                dt.Rows[i]["主轨载频编码"] = sb[0];
                dt.Rows[i]["小轨载频编码"] = sb[1];
                dt.Rows[i]["主轨低频编码"] = sb[2];
                dt.Rows[i]["小轨低频编码"] = sb[3];
            }
        }
        #endregion
    }

    public static class c_Device            //设备,基于设备的表格，MsgGather库的配置
    {
        static public List<objConfigAnalog> AnalogcCollocation = new List<objConfigAnalog>();   //实际配置的模拟量
        /// <summary>
        /// MsgGather.ini
        /// </summary>
        static public Dictionary<string, objMsgGatherStruct> DeviceMsgGather = new Dictionary<string, objMsgGatherStruct>();
        static public Dictionary<string, string> MsgDataBaseTable = new Dictionary<string, string>();   //设备类型对应的数据库表名称

        /// <summary>
        /// dc.ini 文件内容
        /// </summary>
        static public Dictionary<string, objAnalogTypeStruct> DC_AnalogConfig = new Dictionary<string, objAnalogTypeStruct>();
        /// <summary>
        /// gd.ini 文件内容
        /// </summary>
        static public Dictionary<string, objAnalogTypeStruct> GD_AnalogConfig = new Dictionary<string, objAnalogTypeStruct>();
        /// <summary>
        /// jc.ini
        /// </summary>
        static public Dictionary<string, objAnalogTypeStruct> JC_AnalogConfig = new Dictionary<string, objAnalogTypeStruct>();
        /// <summary>
        /// ZH.ini
        /// </summary>
        static public Dictionary<string, objAnalogTypeStruct> ZH_AnalogConfig = new Dictionary<string, objAnalogTypeStruct>();
        /// <summary>
        /// yp.ini
        /// </summary>
        static public Dictionary<string, objAnalogTypeStruct> YP_AnalogConfig = new Dictionary<string, objAnalogTypeStruct>();
        /// <summary>
        /// 道岔缺口配置
        /// </summary>
        static public Dictionary<string, objAnalogTypeStruct> DCQK_AnlogConfig = new Dictionary<string, objAnalogTypeStruct>();
        /// <summary>
        /// 环境监控配置
        /// </summary>
        static public Dictionary<string, objAnalogTypeStruct> HK_AnlogConfig = new Dictionary<string, objAnalogTypeStruct>();
        /// <summary>
        /// xhj.ini
        /// </summary>
        static public objXHJ_TypeStruct XHJ_DSAlarmConfig = new objXHJ_TypeStruct();
        /// <summary>
        /// lk1.ini
        /// </summary>
        static public objLkInfoClass LK1_Config = new objLkInfoClass();
        /// <summary>
        /// digit.int
        /// </summary>
        static public List<kglstuct_Struct> KGL_Config = new List<kglstuct_Struct>();
        /// <summary>
        /// msggather.ini
        /// </summary>
        static public List<objXHJAbnormalShut_Struct> XHJAbnormalShut = new List<objXHJAbnormalShut_Struct>();

        static public List<objFLBL_Struct> FLBL_Config = new List<objFLBL_Struct>();

        static public Dictionary<int, List<string>> Alarm_ConfigList = new Dictionary<int, List<string>>();        
        
        #region 高压不对称电压波形
        static public List<string> GybdcDYbx_DevList = new List<string>();
        static public void InitGybdcDYbx_DevList()
        {
            if (GD_AnalogConfig.ContainsKey("高压不对称电压波形"))
            {
                for (int i = 0; i < GD_AnalogConfig["高压不对称电压波形"].AnalogList.Count; i++)
                {
                    GybdcDYbx_DevList.Add(GD_AnalogConfig["高压不对称电压波形"].AnalogList[i].AnalogName);
                }
            }
        }
        static public string GetGybdcDyDevName(int devNo)
        {            
            if (devNo >= 0 && devNo < GybdcDYbx_DevList.Count)
            {
                return GybdcDYbx_DevList[devNo];
            }
            return "";
        }
        static public int GetGybdcDyDevNo(string Name)
        {
            //return 1;
            if (GybdcDYbx_DevList.Contains(Name))
            {
                for (int i = 0; i < GybdcDYbx_DevList.Count; i++)
                {
                    if (Name == GybdcDYbx_DevList[i]) return i;
                }
            }
            return -1;
        }

        static public objSingleAnalogStruct GetGybdcqx_AnalogConfigSet(int devNo)
        {
            if (devNo >= 0 && devNo < GD_AnalogConfig["高压不对称电压波形"].AnalogList.Count)
            {
                return GD_AnalogConfig["高压不对称电压波形"].AnalogList[devNo];
            }
            return new objSingleAnalogStruct();
        }
        #endregion

        #region 绝缘漏流残压
        static public List<string> CY_DevList = new List<string>();
        static public void InitCy_DevList()
        {
            if (GD_AnalogConfig.ContainsKey("轨道电压"))
            {
                for (int i = 0; i < GD_AnalogConfig["轨道电压"].AnalogList.Count; i++)
                {
                    CY_DevList.Add(GD_AnalogConfig["轨道电压"].AnalogList[i].AnalogName);
                }
            }
        }
        static public string GetJyLlCyDevName(string typeName, int DevNo)
        {
            if(c_Device.DeviceMsgGather.ContainsKey(typeName))
            {
                int len = c_Device.DeviceMsgGather[typeName].DevList.Count;
                if (DevNo >= 0 && DevNo < len)
                {
                    return c_Device.DeviceMsgGather[typeName].DevList[DevNo].DevName;
                } 
            }
            else if(typeName.Contains("残压"))
            {
                if (DevNo >= 0 && DevNo < CY_DevList.Count)
                {
                    return CY_DevList[DevNo];
                }
            }            
            return "";
        }
        static public int GetJyLlCyDevNo(string typeName, string DevName)
        {
            if (DeviceMsgGather.ContainsKey(typeName))
            {
                int len = DeviceMsgGather[typeName].DevList.Count;
                for (int i = 0; i < len; i++)
                {
                    string tmp = DeviceMsgGather[typeName].DevList[i].DevName;
                    if (DevName == tmp) return i;
                }
            }
            else if (typeName.Contains("残压"))
            {
                int len = CY_DevList.Count;
                for (int i = 0; i < len; i++)
                {
                    if (DevName == CY_DevList[i]) return i;
                }
            }
            return -1;
        }

        static public objSingleAnalogStruct GetJySingleAnalogConfigSet(int devNo)
        {
            if (devNo >= 0 && devNo < ZH_AnalogConfig["电缆绝缘"].AnalogList.Count)
            {
                return ZH_AnalogConfig["电缆绝缘"].AnalogList[devNo];
            }
            return new objSingleAnalogStruct();
        }
        static public objSingleAnalogStruct GetLlSingleAnalogConfigSet(int devNo)
        {
            if (devNo >= 0 && devNo < ZH_AnalogConfig["电源漏流"].AnalogList.Count)
            {
                return ZH_AnalogConfig["电源漏流"].AnalogList[devNo];
            }
            return new objSingleAnalogStruct();
        }
        static public objSingleAnalogStruct GetCySingleAnalogConfigSet(int devNo)
        {
            if (devNo >= 0 && devNo < GD_AnalogConfig["轨道电压"].AnalogList.Count)
            {
                return GD_AnalogConfig["轨道电压"].AnalogList[devNo];
            }
            return new objSingleAnalogStruct();
        }
        #endregion

        #region 外电网故障曲线
        static public List<string> WdwErrorQX_DevList = new List<string>();
        static public void InitWdwErrorQX_DevList()
        {
            WdwErrorQX_DevList.Add("I路");
            WdwErrorQX_DevList.Add("II路");
        }
        static public int GetWdwErrorQX_DevNo(string DevName)
        {
            for (int i = 0; i < WdwErrorQX_DevList.Count; i++)
            {
                if (WdwErrorQX_DevList[i] == DevName) return i;
            }
            return -1;
        }
        #endregion

        #region 道岔电流、功率曲线设备表
        static public List<objDcdlqxStruct> DcdlqxDevList = new List<objDcdlqxStruct>();
        static public void InitDcdlqxDevList()
        {
            if (DC_AnalogConfig.ContainsKey("道岔动作电流"))
            {
                int len = DC_AnalogConfig["道岔动作电流"].AnalogList.Count;
                for (int i = 0; i < len; i++)
                {
                    string s = DC_AnalogConfig["道岔动作电流"].AnalogList[i].AnalogName;
                    if (s != "DUMMY" && !s.Contains("功率"))
                    {
                        objDcdlqxStruct obj = new objDcdlqxStruct();
                        obj.DevName = s;
                        obj.DevNo = DC_AnalogConfig["道岔动作电流"].AnalogList[i].ADNumber;
                        obj.Flag = DC_AnalogConfig["道岔动作电流"].AnalogList[i].Flag;
                        DcdlqxDevList.Add(obj);
                    }
                }
            }
        }
        static public int GetDcdlqxDevNo(string DevName)
        {
            for (int i = 0; i < DcdlqxDevList.Count; i++)
            {
                if (DcdlqxDevList[i].DevName == DevName) return DcdlqxDevList[i].DevNo;
            }
            return -1;
        }
        static public string GetDcdlqxDevName(int DevNo)
        {
            for (int i = 0; i < DcdlqxDevList.Count; i++)
            {
                if (DcdlqxDevList[i].DevNo == DevNo) return DcdlqxDevList[i].DevName;
            }
            return "";
        }
        /// <summary>
        /// 获得道岔的类型，0为普通道岔，只有一条曲线，其它为提速道岔，4条曲线，-1为获取失败
        /// </summary>
        /// <param name="DevNo"></param>
        /// <returns></returns>
        static public int GetDctype(int DevNo)
        {
            if ((DevNo < DcdlqxDevList.Count)&&(DevNo>=0))
            {
                return DcdlqxDevList[DevNo].Flag;
            }
            return -1;
        }
        /// <summary>
        /// 获得道岔电流曲线的配置
        /// </summary>
        /// <param name="devNo"></param> 设备序号，使用GetDcdlqxDevNo，A向，B向，C向，功率为同一个序号
        /// <param name="flag"></param>标准，0表示取A向，1表示取B向，2-C向，3-功率
        /// <returns></returns>
        static public objSingleAnalogStruct GetDCdlqxSingleAnalogConfigSet(int devNo, int flag)
        {
            if (devNo >= 0 && devNo < DC_AnalogConfig["道岔动作电流"].AnalogList.Count)
            {
                if (flag >= 0 && flag <= 3)
                {
                    devNo += flag;
                    return DC_AnalogConfig["道岔动作电流"].AnalogList[devNo];
                }
            }
            return new objSingleAnalogStruct();
        }
        #endregion

        #region 系统日志配置
        static public List<string> SysLogConfig = new List<string>();
        static public void InitSysLogConfig()
        {
            SysLogConfig.Add("系统工作日志");
            SysLogConfig.Add("用户操作日志");
            SysLogConfig.Add("天窗作业日志");
            SysLogConfig.Add("时钟校时日志");
            SysLogConfig.Add("按钮操作记录日志");
        }
        static public int GetSysLogID(string LogTypeName)
        {
            if (LogTypeName == "系统工作日志") return 1;
            if (LogTypeName == "用户操作日志") return 2;
            if (LogTypeName == "天窗作业日志") return 3;
            if (LogTypeName == "时钟校时日志") return 4;
            if (LogTypeName == "按钮操作记录日志") return 5;
            return -1;
        }
        static public string GetSysLogTypeName(int LogID)
        {
            if (LogID == 1) return "系统工作日志";
            if (LogID == 2) return "用户操作日志";
            if (LogID == 3) return "天窗作业日志";
            if (LogID == 4) return "时钟校时日志";
            if (LogID == 5) return "按钮操作记录日志";
            return "";
        }
        #endregion

        #region 用户浏览记录配置
        /// <summary>
        /// 用户浏览记录配置表，通过MsgGather生成
        /// 使用类型名称为键值，规划为3个键值，1为模拟量浏览记录，2为道岔动作电流浏览记录，3为报警浏览记录
        /// 模拟量浏览记录 名称为模拟量类型名称+菜单名
        /// 道岔动作电流浏览 名称为 转辙机名称+动作电流
        /// 报警浏览记录 名称为 报警类型
        /// </summary>
        static public Dictionary<string, List<string>> UserScanAnnalConfig = new Dictionary<string, List<string>>();   //用户浏览记录配置表

        /// <summary>
        /// 初始化用户浏览报表记录
        /// </summary>
        static public void InitUserScanAnnalConfig()
        {
            string KeyName = "";
            KeyName = "设备浏览记录";
            List<string> NameList = new List<string>();
            foreach (string key in DeviceMsgGather.Keys)
            {
                string TmpName = key;
                int len = DeviceMsgGather[key].MenuList.Count;
                NameList.Add(TmpName + "实时值");
                for (int i = 0; i < len; i++)
                {
                    string strMenu = string.Empty;
                    if (TmpName == "转辙机")
                    {
                        if (DeviceMsgGather[key].MenuList[i].MenuName.Contains("动作")) { }   //道岔动作电流单独是一个菜单
                        else
                        {
                            strMenu += DeviceMsgGather[key].MenuList[i].MenuName;
                            NameList.Add(TmpName + strMenu);
                        }
                    }
                    else
                    {
                        strMenu += DeviceMsgGather[key].MenuList[i].MenuName;
                        NameList.Add(TmpName + strMenu);
                    }
                   
                }
            }

            UserScanAnnalConfig.Add(KeyName, NameList);         //加入到配置表中
            KeyName = "道岔动作电流曲线浏览记录";
            NameList = new List<string>();
            if (DC_AnalogConfig.ContainsKey("道岔动作电流"))
            {
                int len = DC_AnalogConfig["道岔动作电流"].AnalogList.Count;
                for (int i = 0; i < len; i++)
                {
                    string TmpName = DC_AnalogConfig["道岔动作电流"].AnalogList[i].AnalogName;
                    if (TmpName != "" && TmpName != "DUMMY")
                    {
                        NameList.Add(TmpName);
                    }
                }
            }


            UserScanAnnalConfig.Add(KeyName, NameList);         //加入到配置表中
            KeyName = "报警浏览记录";
            NameList = new List<string>();
            //报警的还未做列表
        }

        static public int GetUserScanTableType(string KeyName)
        {
            if (KeyName == "设备浏览记录") return 0;
            else if (KeyName == "道岔动作电流曲线浏览记录") return 1;
            else if (KeyName == "报警浏览记录") return 2;
            return -1;
        }
        /// <summary>
        /// 获得报表在配置中的ID号，存入数据库中使用该ID号码
        /// </summary>
        /// <param name="KeyName"></param>
        /// <param name="MenuName"></param>
        /// <returns></returns>
        static public int GetUserScanTableNo(string KeyName, string MenuName)
        {
            if (UserScanAnnalConfig.ContainsKey(KeyName))
            {
                int len = UserScanAnnalConfig[KeyName].Count;
                for (int i = 0; i < len; i++)
                {
                    if (MenuName == UserScanAnnalConfig[KeyName][i])
                    {
                        return i;       //找到了所在列表的序号.
                    }
                }
            }
            return -1;
        }

        static public string GetUserScanTableName(int keyNo, int devNo)
        {
            if (keyNo >= UserScanAnnalConfig.Count) return "";
            if (devNo < 0 || keyNo<0) return "";
            string KeyName = "";
            if(keyNo == 0) KeyName = "设备浏览记录";
            else if(keyNo == 1) KeyName = "道岔动作电流曲线浏览记录";
            else if(keyNo == 2) KeyName = "报警浏览记录";
            if (devNo < 0) return "";
            if (devNo >= UserScanAnnalConfig[KeyName].Count) return "";
            else return UserScanAnnalConfig[KeyName][devNo];
        }
        #endregion

        #region 统计类报表配置
        /// <summary>
        /// 统计类报表配置
        /// 以统计类型做键值，内容为每种统计的设备列表, 类型和设备都从1开始编号
        /// 设备序号和类型序号需和逻辑处理进程保持一致。
        /// </summary>
        static public Dictionary<string, List<objtjDev>> TongJiConfig = new Dictionary<string, List<objtjDev>>();

        static public void InitTongJiConfig()
        {
            List<objtjDev> DevList0 = new List<objtjDev>();
            List<objtjDev> DevList1 = new List<objtjDev>();
            List<objtjDev> DevList2 = new List<objtjDev>();
            List<objtjDev> DevList3 = new List<objtjDev>();
            List<objtjDev> DevList4 = new List<objtjDev>();
            int len = KGL_Config.Count;
            for (int i = 0; i < len; i++)
            {
                if (KGL_Config[i].Type == 0)
                {
                    objtjDev t= new objtjDev();
                    t.DevName = KGL_Config[i].Name;
                    t.devNo = KGL_Config[i].ADNumber;
                    DevList0.Add(t);
                }
                else if (KGL_Config[i].Type == 1)
                {
                    objtjDev t = new objtjDev();
                    t.DevName = KGL_Config[i].Name;
                    t.devNo = KGL_Config[i].ADNumber;
                    DevList1.Add(t);
                }
                else if (KGL_Config[i].Type == 2)
                {
                    objtjDev t = new objtjDev();
                    t.DevName = KGL_Config[i].Name;
                    t.devNo = KGL_Config[i].ADNumber;
                    DevList2.Add(t);
                }
                else if (KGL_Config[i].Type == 3)
                {
                    objtjDev t = new objtjDev();
                    t.DevName = KGL_Config[i].Name;
                    t.devNo = KGL_Config[i].ADNumber;
                    DevList3.Add(t);
                }
                else if (KGL_Config[i].Type == 25)
                {
                    objtjDev t = new objtjDev();
                    t.DevName = KGL_Config[i].Name;
                    t.devNo = KGL_Config[i].ADNumber;
                    DevList4.Add(t);
                }
            }
            string KeyName = "破封按钮运用次数统计";
            TongJiConfig.Add(KeyName, DevList0);
            KeyName = "区段占用次数统计";
            TongJiConfig.Add(KeyName, DevList1);
            KeyName = "信号机开放次数统计";
            TongJiConfig.Add(KeyName, DevList2);
            KeyName = "列调按钮运用次数统计";
            TongJiConfig.Add(KeyName, DevList3);
            KeyName = "故障通知按钮运用次数统计";
            TongJiConfig.Add(KeyName, DevList4);
            
            len = DC_AnalogConfig["道岔动作电流"].AnalogList.Count;
            List<objtjDev> DevListdc = new List<objtjDev>();
            for (int i = 0; i < len; i++)
            {
                int flag = DC_AnalogConfig["道岔动作电流"].AnalogList[i].Flag;
                if (flag == 0 || flag == 1)
                {
                    string DCname = DC_AnalogConfig["道岔动作电流"].AnalogList[i].AnalogName;
                    if (DCname != "DUMMY")
                    {
                        objtjDev t = new objtjDev();
                        t.DevName = DCname;
                        t.devNo = DC_AnalogConfig["道岔动作电流"].AnalogList[i].ADNumber;
                        DevListdc.Add(t);
                    }
                }
            }
            KeyName = "道岔动作次数统计";
            TongJiConfig.Add(KeyName, DevListdc);
            
            List<objtjDev> DevListAlarm = new List<objtjDev>();

            foreach(int key in Alarm_ConfigList.Keys)
            {
                for (int j = 0; j < Alarm_ConfigList[key].Count; j++)
                {
                    objtjDev t = new objtjDev();
                    t.DevName = Alarm_ConfigList[key][j];
                    t.devNo = GetAlarmTypeCode(t.DevName);
                    if (t.devNo == -1) MessageBox.Show("报警类型错误");
                    DevListAlarm.Add(t);
                }
            }
            KeyName = "设备故障次数统计";
            TongJiConfig.Add(KeyName, DevListAlarm);
        }

        static public int GetTongJiType(string KeyName)
        {
            if (KeyName == "破封按钮运用次数统计") return 0x64;
            else if (KeyName == "区段占用次数统计") return 0x61;
            else if (KeyName == "信号机开放次数统计") return 0x62;
            else if (KeyName == "列调按钮运用次数统计") return 0x63;
            else if (KeyName == "设备故障次数统计") return 0x65;
            else if (KeyName == "道岔动作次数统计") return 0x60;
            else if (KeyName == "故障通知按钮运用次数统计") return 0x66;    //协议中未有的
            return -1;
        }

        static public string GetTongJiTypeName(int n)
        {
            if (0x64 == n) return "破封按钮运用次数统计";
            if (0x61 == n) return "区段占用次数统计";
            if (0x62 == n) return "信号机开放次数统计";
            if (0x63 == n) return "列调按钮运用次数统计";
            if (0x65 == n) return "设备故障次数统计";
            if (0x60 == n) return "道岔动作次数统计";
            if (0x66 == n) return "故障通知按钮运用次数统计";
            return "";
        }

        static public int GetTongJiDevNo(string KeyName, string DevName)
        {
            if (TongJiConfig.ContainsKey(KeyName))
            {
                int len = TongJiConfig[KeyName].Count;
                for (int i = 0; i < len; i++)
                {
                    if(DevName == TongJiConfig[KeyName][i].DevName) return (TongJiConfig[KeyName][i].devNo);
                }
            }
            return -1;
        }

        static public string GetTongJiDevName(int devType, int devno)
        {
            string keyName = "";
            //if (devType <= 0 || devno <= 0) return "";
            if (0x64 == devType) keyName = "破封按钮运用次数统计";
            else if (0x61 == devType) keyName = "区段占用次数统计";
            else if (0x62 == devType) keyName = "信号机开放次数统计";
            else if (0x63 == devType) keyName = "列调按钮运用次数统计";
            else if (0x65 == devType) keyName = "设备故障次数统计";
            else if (0x60 == devType) keyName = "道岔动作次数统计";
            else if (0x66 == devType) keyName = "故障通知按钮运用次数统计";
            else return "";
            if (TongJiConfig.ContainsKey(keyName))
            {
                foreach (objtjDev obj in TongJiConfig[keyName])
                {
                    if (obj.devNo == devno) return obj.DevName;
                }                
            }
            return "";
        }

        #endregion

        #region 按钮使用记录
        public struct objButtenStruct
        {
            public int devNo;
            public string devName;
        }
        static public List<objButtenStruct> ButtenUseConfig = new List<objButtenStruct>();

        static public void InitButtenUseConfig()
        {
            ButtenUseConfig.Clear();
            int len = KGL_Config.Count;            
            for (int i = 0; i < len; i++)
            {
                if (KGL_Config[i].Type == 0 || KGL_Config[i].Type == 3)
                {
                    objButtenStruct t = new objButtenStruct();
                    t.devName = KGL_Config[i].Name;
                    t.devNo = i + 1;
                    ButtenUseConfig.Add(t);
                }
            }
        }
        static public string GetButtenUseDevName(int devNo)
        {
            if (devNo < 0) return "";
            foreach (objButtenStruct obj in ButtenUseConfig)
            {
                if (obj.devNo == devNo) return obj.devName;
            }
            return "";
        }
        #endregion

        /// <summary>
        /// 判断是否是有效的模拟量类型
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        static public bool IsValidAnalogType(object t)
        {
            if(Enum.IsDefined(typeof(AnalogCodeType), t)) return true;
            return false;
        }

        /// <summary>
        /// 依据模拟量类型，获得模拟量名称
        /// </summary>
        /// <param name="AnalogType"></param>
        /// <returns></returns>
        static public string GetAnalogTypeName(AnalogCodeType AnalogType)
        {
            if (!IsValidAnalogType(AnalogType)) return "";
            object o;
            try
            {
                o = Enum.Parse(typeof(AnalogCodeType), AnalogType.ToString());
            }
            catch
            {
                return "";
            }
            AnalogCodeType t = (AnalogCodeType)o;
            return t.ToString();
        }

        /// <summary>
        /// 获取设备类型名称
        /// </summary>
        /// <param name="csmType"></param>
        /// <returns></returns>
        static public string GetDevTypeName(CSM_DevType csmType)
        {
            object o;
            try
            {
                o = Enum.Parse(typeof(CSM_DevType), csmType.ToString());
            }
            catch
            {
                return "";
            }
            CSM_DevType t = (CSM_DevType)o;
            return t.ToString();
        }

        /// <summary>
        /// 依据报警类型码得到报警类型的名称
        /// </summary>
        /// <param name="TypeNo"></param>
        /// <returns></returns>
        static public string GetAlarmTypeName(int TypeCode)
        {
            string s = "未知类型";
            switch (TypeCode)
            {
                case 0x01:
                    s = "SJ锁闭封连报警";
                    break;
                case 0x02:
                    s = "道岔表示不一致";
                    break;
                case 0x03:
                    s = "挤岔";
                    break;
                case 0x04:
                    s = "列车信号非正常关闭";
                    break;
                case 0x05:
                    s = "火灾";
                    break;
                case 0x06:
                    s = "故障通知按钮";
                    break;
                case 0x07:
                    s = @"外电网输入电源断相/断电报警";
                    break;
                case 0x08:
                    s = "外电网三相电源错序报警";
                    break;
                case 0x09:
                    s = "外电网输入电源瞬间断电报警";
                    break;
                case 0x0a:
                    s = "列车信号主灯丝断丝报警";
                    break;
                case 0x0b:
                    s = "熔丝断丝报警";
                    break;
                case 0x0c:
                    s = "转辙机表示缺口报警";
                    break;
                case 0x0d:
                    s = "区间设备报警";
                    break;
                case 0x0e:
                    s = "微机监测内部采集通信故障报警";
                    break;
                case 0x0f:
                    s = "环境监测报警";
                    break;
                case 0x10:
                    s = @"TDCS/CTC系统报警";
                    break;
                case 0x11:
                    s = "列控系统报警";
                    break;
                case 0x12:
                    s = "计算机联锁系统报警";
                    break;
                case 0x13:
                    s = "电气特性超限报警";
                    break;
                case 0x14:
                    s = "监测与其他系统通信接口故障报警";
                    break;
                case 0x16:
                    s = "道岔运用次数超限预警";
                    break;
                case 0x17:
                    s = "补偿电容断线预警";
                    break;
                case 0x18:
                    s = "ZPW2000系统报警";
                    break;
                case 0x1a:
                    s = "应答器报警";
                    break;
                case 0x1b:
                    s = "智能电源屏报警";
                    break;
                case 0x22:
                    s = "防灾异物侵限报警";
                    break;
                case 0x26:
                    s = "TSRS设备报警";
                    break;
                case 0x27:
                    s = "RBC报警";
                    break;
                case 0x28:
                    s = "电源屏输出断电报警";
                    break;
                case 0x29:
                    s = "道岔无表示报警";
                    break;
                case 0x30:
                    s = @"各种设备模拟量变化趋势、突变、异常波动预警";
                    break;
                case 0x53:
                    s = "控制台按钮操作记录";
                    break;
                case 0x58:
                    s = "轨道长期占用报警";
                    break;
                case 0x62:
                    s = "智能分析预警";
                    break;
                case 0x64:
                    s = "智能分析故障诊断";
                    break;                
            }
            return s;
        }
        /// <summary>
        /// 依据报警类型名称获得报警的序号
        /// </summary>
        /// <param name="typeName"></param>
        /// <returns></returns>
        static public int GetAlarmTypeCode(string typeName)
        {
            string s = typeName;

            if (s.Contains("SJ锁闭封连报警")) return 1;
            if (s.Contains("道岔表示不一致")) return 2;
            if (s.Contains("挤岔")) return 3;
            if (s.Contains("列车信号非正常关闭")) return 4;
            if (s.Contains("火灾")) return 5;
            if (s.Contains("故障通知按钮")) return 6;
            if (s.Contains("外电网输入电源断相")) return 7;
            if (s.Contains("外电网三相电源错序报警")) return 8;
            if (s.Contains("外电网输入电源瞬间断电报警")) return 9;
            if (s.Contains("列车信号主灯丝断丝报警")) return 0x0a;
            if (s.Contains("熔丝断丝报警")) return 0x0b;
            if (s.Contains("转辙机表示缺口报警")) return 0x0c;
            if (s.Contains("区间设备报警")) return 0x0d;
            if (s.Contains("微机监测内部采集通信故障报警")) return 0x0e;
            if (s.Contains("环境监测报警")) return 0x0f;
            if (s.Contains(@"TDCS/CTC系统报警")) return 0x10;
            if (s.Contains("列控系统报警")) return 0x11;
            if (s.Contains("计算机联锁系统报警")) return 0x12;
            if (s.Contains("电气特性超限报警")) return 0x13;

            if (s.Contains("监测与其他系统通信接口故障报警")) return 0x14;
            if (s.Contains("道岔运用次数超限预警")) return 0x16;
            if (s.Contains("补偿电容断线预警")) return 0x17;
            if (s.Contains("ZPW-2000系统报警")) return 0x18;
            if (s.Contains("应答器报警")) return 0x1a;
            if (s.Contains("智能电源屏报警")) return 0x1b;
            if (s.Contains("防灾异物侵限报警")) return 0x22;
            if (s.Contains("TSRS设备报警")) return 0x26;

            if (s.Contains("RBC报警")) return 0x27;
            if (s.Contains("电源屏输出断电报警")) return 0x28;
            if (s.Contains("道岔无表示报警")) return 0x29;
            if (s.Contains("各种设备模拟量变化趋势")) return 0x30;
            if (s.Contains("控制台按钮操作记录")) return 0x53;
            if (s.Contains("轨道长期占用报警")) return 0x58;
            if (s.Contains("智能分析预警")) return 0x62;
            if (s.Contains("智能分析故障诊断")) return 0x64;
            return -1;
        }

        
        /// <summary>
        /// 依据模拟量类型名称 得到该模拟量所在的INI文件名称
        /// </summary>
        /// <param name="TypeName"></param>
        /// <returns></returns>
        static public string GetIniFileFromAnalogTypeName(string TypeName)
        {
            foreach (objConfigAnalog obj in c_Device.AnalogcCollocation)            
            {
                if (obj.TypeName == TypeName)
                {
                    return obj.IniFileName;
                }
            }
            return "";
        }

        /// <summary>
        /// 依据设备类型名和设备属性名得到该属性的模拟量类型名称
        /// </summary>
        /// <param name="DevTypeStr"></param>
        /// <param name="AttriStr"></param>
        /// <returns></returns>
        static public string GetAnalogTypeNameFromDevAttriName(string DevTypeStr, string AttriStr)
        {
            string AnalogTypeName = "";
            if (c_Device.DeviceMsgGather.ContainsKey(DevTypeStr))
            {
                for (int i = 0; i < DeviceMsgGather[DevTypeStr].ArrtiList.Count; i++)
                {
                    if (DeviceMsgGather[DevTypeStr].ArrtiList[i].AttriName == AttriStr)
                    {
                        AnalogCodeType t = DeviceMsgGather[DevTypeStr].ArrtiList[i].AnalogType;
                        AnalogTypeName = GetAnalogTypeName(t);
                        break;
                    }
                }
            }
            return AnalogTypeName;
        }
        /// <summary>
        /// 依据设备类型名称，和模拟量序号，查找 模拟量名称。
        /// </summary>
        /// <param name="devType"></param>
        /// <param name="DevNo"></param>
        /// <returns></returns>
        static public string GetCsm_DevName(CSM_DevType devType,int DevNo)
        {
            if (DevNo == -1) return "";
            string type = GetDevTypeName(devType);
            if(DeviceMsgGather.ContainsKey(type))
            {
                foreach(objMsgDevStruct k in DeviceMsgGather[type].DevList)
                {
                    for(int i = 0;i<k.AnalogSet.Count;i++)
                    {
                        if(k.AnalogSet[i] == DevNo) return k.DevName;
                    }
                }
            }
            return "";
        }
        /// <summary>
        /// 从模拟量互联互通码得到设备类型
        /// </summary>
        /// <param name="Type"></param>
        /// <returns></returns>
        static public CSM_DevType GetCSM_DevType(AnalogCodeType Type)
        {
            CSM_DevType DevType = CSM_DevType.None;
            switch (Type)
            {
                case AnalogCodeType.ups:
                    DevType = CSM_DevType.ups;
                    break;
                case AnalogCodeType.ZPW2000A接口信息:
                    DevType = CSM_DevType.区间轨道电路;
                    break;
                case AnalogCodeType.半自动闭塞电压和电流:
                    DevType = CSM_DevType.半自闭;
                    break;
                case AnalogCodeType.道岔表示电压:
                    DevType = CSM_DevType.转辙机;
                    break;
                case AnalogCodeType.道岔缺口:
                    DevType = CSM_DevType.转辙机;
                    break;
                case AnalogCodeType.道床电阻:
                    DevType = CSM_DevType.区间轨道电路;
                    break;
                case AnalogCodeType.灯丝继电器电流:
                    DevType = CSM_DevType.信号机;
                    break;
                case AnalogCodeType.灯丝继电器电压:
                    DevType = CSM_DevType.信号机;
                    break;
                case AnalogCodeType.电缆绝缘:
                    DevType = CSM_DevType.绝缘;
                    break;
                case AnalogCodeType.电码化低频:
                    DevType = CSM_DevType.电码化;
                    break;
                case AnalogCodeType.电码化发送电流:
                    DevType = CSM_DevType.电码化;
                    break;
                case AnalogCodeType.电码化发送电压:
                    DevType = CSM_DevType.电码化;
                    break;
                case AnalogCodeType.电码化上边频:
                    DevType = CSM_DevType.电码化;
                    break;
                case AnalogCodeType.电码化下边频:
                    DevType = CSM_DevType.电码化;
                    break;
                case AnalogCodeType.电码化载频:
                    DevType = CSM_DevType.电码化;
                    break;
                case AnalogCodeType.电源漏流:
                    DevType = CSM_DevType.漏流;
                    break;
                case AnalogCodeType.电源屏:
                    DevType = CSM_DevType.电源屏;
                    break;
                case AnalogCodeType.分路残压:
                    DevType = CSM_DevType.残压;
                    break;
                case AnalogCodeType.高压不对称:
                    DevType = CSM_DevType.脉冲轨道电路;
                    break;
                case AnalogCodeType.轨出1低频:
                    DevType = CSM_DevType.区间轨道电路;
                    break;
                case AnalogCodeType.轨出1电压:
                    DevType = CSM_DevType.区间轨道电路;
                    break;
                case AnalogCodeType.轨出1分路残压:
                    DevType = CSM_DevType.区间轨道电路;
                    break;
                case AnalogCodeType.轨出1上边频:
                    DevType = CSM_DevType.区间轨道电路;
                    break;
                case AnalogCodeType.轨出1下边频:
                    DevType = CSM_DevType.区间轨道电路;
                    break;
                case AnalogCodeType.轨出1载频:
                    DevType = CSM_DevType.区间轨道电路;
                    break;
                case AnalogCodeType.轨出2低频:
                    DevType = CSM_DevType.区间轨道电路;
                    break;
                case AnalogCodeType.轨出2电压:
                    DevType = CSM_DevType.区间轨道电路;
                    break;
                case AnalogCodeType.轨出2载频:
                    DevType = CSM_DevType.区间轨道电路;
                    break;
                case AnalogCodeType.轨道编码:
                    DevType = CSM_DevType.区间轨道电路;
                    break;
                case AnalogCodeType.轨道电流:
                    DevType = CSM_DevType.站内轨道电路;
                    break;
                case AnalogCodeType.轨道电压:
                    DevType = CSM_DevType.站内轨道电路;
                    break;
                case AnalogCodeType.轨道相位角:
                    DevType = CSM_DevType.站内轨道电路;
                    break;
                case AnalogCodeType.轨道直流电压:
                    DevType = CSM_DevType.站内轨道电路;
                    break;
                case AnalogCodeType.环境模拟量:
                    DevType = CSM_DevType.环境检测;
                    break;
                case AnalogCodeType.计轴:
                    DevType = CSM_DevType.计轴;
                    break;
                case AnalogCodeType.空调参数:
                    break;
                case AnalogCodeType.牵引电流干扰电压:
                    DevType = CSM_DevType.站内轨道电路;
                    break;
                case AnalogCodeType.外电网:
                    DevType = CSM_DevType.外电网;
                    break;
                case AnalogCodeType.小轨轨入电压:
                    DevType = CSM_DevType.区间轨道电路;
                    break;
                case AnalogCodeType.移频发送电缆侧电流:
                    DevType = CSM_DevType.区间轨道电路;
                    break;
                case AnalogCodeType.移频发送电缆侧电压:
                    DevType = CSM_DevType.区间轨道电路;
                    break;
                case AnalogCodeType.移频发送器低频:
                    DevType = CSM_DevType.区间轨道电路;
                    break;
                case AnalogCodeType.移频发送器发送电流:
                    DevType = CSM_DevType.区间轨道电路;
                    break;
                case AnalogCodeType.移频发送器发送电压:
                    DevType = CSM_DevType.区间轨道电路;
                    break;
                case AnalogCodeType.移频发送器载频:
                    DevType = CSM_DevType.区间轨道电路;
                    break;
                case AnalogCodeType.移频接收电缆侧电压:
                    DevType = CSM_DevType.区间轨道电路;
                    break;
                case AnalogCodeType.异物继电器端电压:
                    DevType = CSM_DevType.防灾;
                    break;
                case AnalogCodeType.站联电压:
                    DevType = CSM_DevType.站联;
                    break;
                case AnalogCodeType.主轨轨入低频:
                    DevType = CSM_DevType.区间轨道电路;
                    break;
                case AnalogCodeType.主轨轨入电压:
                    DevType = CSM_DevType.区间轨道电路;
                    break;
                case AnalogCodeType.主轨轨入载频:
                    DevType = CSM_DevType.区间轨道电路;
                    break;
                case AnalogCodeType.转辙机功率:
                    DevType = CSM_DevType.None;
                    break;
                case AnalogCodeType.区间室外监测:
                    DevType = CSM_DevType.区间监测;
                    break;
            }
            return DevType;
        }
        /// <summary>
        /// 依据模拟量名称获得模拟量类型
        /// </summary>
        /// <param name="AnalogName"></param>
        /// <returns></returns>
        static public AnalogCodeType GetAnalogTypeFromName(string AnalogName)
        {
           int k =  Convert.ToInt32(Enum.Parse(typeof(AnalogCodeType), AnalogName));
           AnalogCodeType r = (AnalogCodeType)k;
           return r;
        }
        /// <summary>
        /// 获得某ge设备的属性，设备号集合
        /// </summary>
        /// <param name="CsmTypeName"></param>
        /// <param name="DevName"></param>
        /// <returns></returns>
        static public List<AnalogObj> GetDevAttributeList(string CsmTypeName, string DevName)
        {
            List<AnalogObj> rli = new List<AnalogObj>();
            if (DeviceMsgGather.ContainsKey(CsmTypeName))
            {
                int len = DeviceMsgGather[CsmTypeName].DevList.Count;
                foreach(objMsgDevStruct key in DeviceMsgGather[CsmTypeName].DevList)
                {
                    if(key.DevName == DevName)
                    {
                        for(int i = 0;i<key.AnalogSet.Count;i++)
                        {
                            if (key.AnalogSet[i] != -1)
                            {
                                AnalogObj obj = new AnalogObj();
                                obj.devNo = key.AnalogSet[i];
                                obj.type = DeviceMsgGather[CsmTypeName].ArrtiList[i].AnalogType;
                                rli.Add(obj);
                            }
                        }
                        break;
                    }
                }                
            }
            return rli;
        }
        /// <summary>
        /// 依据设备类型名，设备名，属性 获得模拟量的类型和模拟量序号集合
        /// </summary>
        /// <param name="CsmTypeName"></param>
        /// <param name="DevName"></param>
        /// <param name="AttriName"></param>
        /// <returns></returns>
        static public AnalogObj GetAnalogDevNo(string CsmTypeName, string DevName, string AttriName)
        {
            AnalogObj obj = new AnalogObj();

            AnalogCodeType tmpType = AnalogCodeType.None;
            int AttriNo = -1;
            int DevNo = -1;
            if (DeviceMsgGather.ContainsKey(CsmTypeName))
            {
                int l = DeviceMsgGather[CsmTypeName].ArrtiList.Count;
                for (int i = 0; i < l; i++)
                {
                   string s = DeviceMsgGather[CsmTypeName].ArrtiList[i].AttriName;
                   if (s == AttriName)
                   {
                       tmpType = DeviceMsgGather[CsmTypeName].ArrtiList[i].AnalogType;
                       AttriNo = i;
                       break;
                   }
                }
                if (AttriNo != -1)      //先找到了属性
                {
                    int len = DeviceMsgGather[CsmTypeName].DevList.Count;
                    for (int i = 0; i < len; i++)
                    {
                        string s = DeviceMsgGather[CsmTypeName].DevList[i].DevName;
                        if (s == DevName)
                        {
                            DevNo = DeviceMsgGather[CsmTypeName].DevList[i].AnalogSet[AttriNo];
                            break;
                        }
                    }
                }
            }
            obj.devNo = DevNo;
            obj.type = tmpType;
            return obj;
        }
        /// <summary>
        /// 根据模拟量类型得到数据库的表名
        /// </summary>
        /// <param name="Type"></param>
        /// <returns></returns>
        static public string GetTableName(AnalogCodeType Type)
        {
            string TableName = "";
            switch (Type)
            {
                case AnalogCodeType.ups:
                    TableName = "ups";
                    break;
                case AnalogCodeType.ZPW2000A接口信息:
                    TableName = "qjgddl";
                    break;
                case AnalogCodeType.半自动闭塞电压和电流:
                    TableName = "HighFreAnalog";
                    break;
                case AnalogCodeType.道岔表示电压:
                    TableName = "dctable";
                    break;
                case AnalogCodeType.道岔缺口:
                    TableName = "dctable";
                    break;
                case AnalogCodeType.道床电阻:
                    TableName = "qjgddl";
                    break;
                case AnalogCodeType.灯丝继电器电流:
                    TableName = "xhj";
                    break;
                case AnalogCodeType.灯丝继电器电压:
                    TableName = "xhj";
                    break;
                case AnalogCodeType.电缆绝缘:
                    TableName = "jy$ll$cy";
                    break;
                case AnalogCodeType.电码化低频:
                    TableName = "dmh";
                    break;
                case AnalogCodeType.电码化发送电流:
                    TableName = "dmh";
                    break;
                case AnalogCodeType.电码化发送电压:
                    TableName = "dmh";
                    break;
                case AnalogCodeType.电码化上边频:
                    TableName = "dmh";
                    break;
                case AnalogCodeType.电码化下边频:
                    TableName = "dmh";
                    break;
                case AnalogCodeType.电码化载频:
                    TableName = "dmh";
                    break;
                case AnalogCodeType.电源漏流:
                    TableName = "jy$ll$cy";
                    break;
                case AnalogCodeType.电源屏:
                    TableName = "dyp";
                    break;
                case AnalogCodeType.分路残压:
                    TableName = "jy$ll$cy";
                    break;
                case AnalogCodeType.高压不对称:
                    TableName = "mcgddl";
                    break;
                case AnalogCodeType.轨出1低频:
                    TableName = "qjgddl";
                    break;
                case AnalogCodeType.轨出1电压:
                    TableName = "qjgddl";
                    break;
                case AnalogCodeType.轨出1分路残压:
                    TableName = "qjgddl";
                    break;
                case AnalogCodeType.轨出1上边频:
                    TableName = "qjgddl";
                    break;
                case AnalogCodeType.轨出1下边频:
                    TableName = "qjgddl";
                    break;
                case AnalogCodeType.轨出1载频:
                    TableName = "qjgddl";
                    break;
                case AnalogCodeType.轨出2低频:
                    TableName = "qjgddl";
                    break;
                case AnalogCodeType.轨出2电压:
                    TableName = "qjgddl";
                    break;
                case AnalogCodeType.轨出2载频:
                    TableName = "qjgddl";
                    break;
                case AnalogCodeType.轨道编码:
                    TableName = "qjgddl";
                    break;
                case AnalogCodeType.轨道电流:
                    TableName = "zngddl";
                    break;
                case AnalogCodeType.轨道电压:
                    TableName = "zngddl";
                    break;
                case AnalogCodeType.轨道相位角:
                    TableName = "zngddl";
                    break;
                case AnalogCodeType.轨道直流电压:
                    TableName = "zngddl";
                    break;
                case AnalogCodeType.环境模拟量:
                    TableName = "hjjcTable";
                    break;
                case AnalogCodeType.计轴:
                    TableName = "jzfz";
                    break;
                case AnalogCodeType.空调参数:
                    break;
                case AnalogCodeType.牵引电流干扰电压:
                    TableName = "zngddl";
                    break;
                case AnalogCodeType.外电网:
                    TableName = "wdw";
                    break;
                case AnalogCodeType.小轨轨入电压:
                    TableName = "qjgddl";
                    break;
                case AnalogCodeType.移频发送电缆侧电流:
                    TableName = "qjgddl";
                    break;
                case AnalogCodeType.移频发送电缆侧电压:
                    TableName = "qjgddl";
                    break;
                case AnalogCodeType.移频发送器低频:
                    TableName = "qjgddl";
                    break;
                case AnalogCodeType.移频发送器发送电流:
                    TableName = "qjgddl";
                    break;
                case AnalogCodeType.移频发送器发送电压:
                    TableName = "qjgddl";
                    break;
                case AnalogCodeType.移频发送器载频:
                    TableName = "qjgddl";
                    break;
                case AnalogCodeType.移频接收电缆侧电压:
                    TableName = "qjgddl";
                    break;
                case AnalogCodeType.异物继电器端电压:
                    TableName = "jzfz";
                    break;
                case AnalogCodeType.站联电压:
                    TableName = "zhanlian";
                    break;
                case AnalogCodeType.主轨轨入低频:
                    TableName = "qjgddl";
                    break;
                case AnalogCodeType.主轨轨入电压:
                    TableName = "qjgddl";
                    break;
                case AnalogCodeType.主轨轨入载频:
                    TableName = "qjgddl";
                    break;
                case AnalogCodeType.转辙机功率:
                    TableName = "dcdlqx";
                    break;
                case AnalogCodeType.区间室外监测:
                    TableName = "qjjc";
                    break;
            }
            return TableName;
        }
        /// <summary>
        /// 根据设备类型名，设备名，属性名获得 该路模拟量在配置库中的配置数据
        /// </summary>
        /// <param name="CsmTypeName"></param>
        /// <param name="DevName"></param>
        /// <param name="AttriName"></param>
        /// <returns></returns>
        static public objSingleAnalogStruct GetSingleAnalogConfig(string CsmTypeName, string DevName, string AttriName)
        {
            //属性名不是模拟量类型名，需要进行转换
            string AnalogTypeName = GetAnalogTypeNameFromDevAttriName(CsmTypeName,AttriName);
            string IniFileName = GetIniFileFromAnalogTypeName(AnalogTypeName);            
            AnalogObj AO = GetAnalogDevNo(CsmTypeName, DevName, AttriName);

            
            int AnalogNo = AO.devNo;

            return GetSingleAnalogConfig_Inf(IniFileName, AnalogNo, AnalogTypeName);            
        }
        /// <summary>
        /// 依据模拟量类型名，获得该模拟量类型的总数
        /// </summary>
        /// <param name="AnalogTypeName"></param>
        /// <returns></returns>
        static public int GetAnalogTypeDevNum(string AnalogTypeName)
        {
            string IniFileName = GetIniFileFromAnalogTypeName(AnalogTypeName);
            if (IniFileName == "gd")
            {
                if (GD_AnalogConfig.ContainsKey(AnalogTypeName)) return GD_AnalogConfig[AnalogTypeName].AnalogNum;
            }
            else if (IniFileName == "jc")
            {
                if (JC_AnalogConfig.ContainsKey(AnalogTypeName)) return JC_AnalogConfig[AnalogTypeName].AnalogNum;
            }
            else if (IniFileName == "zh")
            {
                if (ZH_AnalogConfig.ContainsKey(AnalogTypeName)) return ZH_AnalogConfig[AnalogTypeName].AnalogNum;
            }
            else if (IniFileName == "yp")
            {
                if (YP_AnalogConfig.ContainsKey(AnalogTypeName)) return YP_AnalogConfig[AnalogTypeName].AnalogNum;
            }
            return 0;
        }
        /// <summary>
        /// 依据模拟量类型，获得该种类型模拟量的数量
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        static public int GetAnalogTypeDevNum(byte type)
        {
            string AnalogTypeName = GetAnalogTypeName((AnalogCodeType)type);
            return GetAnalogTypeDevNum(AnalogTypeName);
        }
        static public objSingleAnalogStruct GetSingleAnalogConfig_Inf(AnalogCodeType atype, int aNo)
        {
            string AnalogTypeName = GetAnalogTypeName(atype);   //模拟量类型名
            string IniFileName = GetIniFileFromAnalogTypeName(AnalogTypeName);
            return GetSingleAnalogConfig_Inf(IniFileName, aNo, AnalogTypeName);
        }
        /// <summary>
        /// 根据INI文件名，模拟量类型名，模拟量序号获得模拟量在配置库中的配置数据
        /// </summary>
        /// <param name="IniFileName"></param>
        /// <param name="AnalogNo"></param>
        /// <param name="AnalogTypeName"></param>
        /// <returns></returns>
        static public objSingleAnalogStruct GetSingleAnalogConfig_Inf(string IniFileName, int AnalogNo, string AnalogTypeName)
        {
            objSingleAnalogStruct objS = new objSingleAnalogStruct();
            
            if (AnalogNo < 0) return new objSingleAnalogStruct();
            if (IniFileName == "gd")
            {
                if (c_Device.GD_AnalogConfig.ContainsKey(AnalogTypeName))
                {
                    objS = c_Device.GD_AnalogConfig[AnalogTypeName].AnalogList[AnalogNo];
                }
            }
            else if (IniFileName == "jc")
            {
                if (c_Device.JC_AnalogConfig.ContainsKey(AnalogTypeName))
                {
                    objS = c_Device.JC_AnalogConfig[AnalogTypeName].AnalogList[AnalogNo];
                }
            }
            else if (IniFileName == "zh")
            {
                if (c_Device.ZH_AnalogConfig.ContainsKey(AnalogTypeName))
                {
                    objS = c_Device.ZH_AnalogConfig[AnalogTypeName].AnalogList[AnalogNo];
                }
            }
            else if (IniFileName == "yp")
            {
                if (c_Device.YP_AnalogConfig.ContainsKey(AnalogTypeName))
                {
                    objS = c_Device.YP_AnalogConfig[AnalogTypeName].AnalogList[AnalogNo];
                }
            }
            else objS = new objSingleAnalogStruct();
            return objS;
        }
        /// <summary>
        /// 根据设备类型，设备名称获得该设备的属性列表
        /// </summary>
        /// <param name="CsmTypeName"></param>
        /// <param name="DevName"></param>
        /// <returns></returns>
        static public List<objMsgAttriStruct> GetDevAttriNameList(string CsmTypeName, string DevName)
        {
            List<objMsgAttriStruct> obj = new List<objMsgAttriStruct>();
            if (DeviceMsgGather.ContainsKey(CsmTypeName))
            {
                for(int i = 0;i<DeviceMsgGather[CsmTypeName].DevList.Count;i++)
                {
                    if (DeviceMsgGather[CsmTypeName].DevList[i].DevName == DevName)
                    {
                        for (int j = 0; j < DeviceMsgGather[CsmTypeName].DevList[i].AnalogSet.Count; j++)
                        {
                            if (DeviceMsgGather[CsmTypeName].DevList[i].AnalogSet[j] != -1)
                            {
                                obj.Add(DeviceMsgGather[CsmTypeName].ArrtiList[j]);
                            }
                        }
                        break;
                    }
                }
            }
            return obj;
        }
        /// <summary>
        /// 已经模拟量类型和模拟量序号，获得模拟量名称
        /// </summary>
        /// <param name="type"></param>
        /// <param name="no"></param>
        /// <returns></returns>
        static public string GetAnalogName(int type, int no)
        {
            string typeName = GetAnalogTypeName((AnalogCodeType)type);
            string IniFile = GetIniFileFromAnalogTypeName(typeName);
            objSingleAnalogStruct objS = GetSingleAnalogConfig_Inf(IniFile, no, typeName);
            return objS.AnalogName;
        }
        /// <summary>
        /// 得到高频模拟量类型的采集频率
        /// 目前只有半自动闭塞电压电流的采集频率为 10.
        /// </summary>
        /// <param name="HighType"></param>
        /// <returns></returns>
        static public int GetHighFrequencyDotNum(byte HighType)        
        {
            if (HighType == 0x42)
            {
                return 10;
            }
            else return 0;
        }
        /// <summary>
        /// 得到开关量名称
        /// </summary>
        /// <param name="no"></param>
        /// <returns></returns>
        static public string GetKGLName(int no)
        {
            foreach (kglstuct_Struct k in KGL_Config)
            {
                if (k.ADNumber == no) return k.Name;
            }
            return "";
        }
        /// <summary>
        /// 查找开关量所对应的设备
        /// </summary>
        /// <param name="no"></param>
        /// <returns></returns>
        static public bool GetKGLInMsgGather(int no,ref string DevType,ref string DevName)
        {
            foreach(KeyValuePair<string,objMsgGatherStruct>msg in DeviceMsgGather)
            {
                for (int x = 0; x < msg.Value.ArrtiList.Count; x++)
                {
                    if (msg.Value.ArrtiList[x].AnalogType != AnalogCodeType.None) continue;
                    for (int i = 0; i < msg.Value.DevList.Count; i++)
                    {
                        if(msg.Value.DevList[i].AnalogSet[x] == no)
                        {
                            DevType = msg.Key;
                            DevName = msg.Value.DevList[i].DevName;
                            return true;
                        }
                    }
                }
            }
            return false;
        }
        /// <summary>
        /// 获得日报表的表头显示
        /// </summary>
        /// <param name="attriName"></param>
        /// <param name="str1"></param>
        /// <param name="str2"></param>
        /// <param name="str3"></param>
        /// <returns></returns>返回实际的有效个数.
        static public int GetDailyTableHeadStr(string CsmType, string attriName, ref string str1, ref string str2, ref string str3)
        {
            int ret = 0;
            string AnalogName = GetAnalogTypeNameFromDevAttriName(CsmType,attriName);
            AnalogCodeType AnalogNo = GetAnalogTypeFromName(AnalogName);
            if (IsValidAnalogType(AnalogNo))
            {
                if (AnalogNo == AnalogCodeType.轨道电压)
                {
                    str1 = "调整最高";
                    str2 = "调整最低";
                    str3 = "分路最高";
                    ret = 3;
                }
                else if (AnalogNo == AnalogCodeType.轨道相位角)
                {
                    str1 = "调整最高";
                    str2 = "调整最低";
                    str3 = "";
                    ret = 2;
                }
                else if (AnalogNo == AnalogCodeType.电码化发送电流)
                {
                    str1 = "空闲最高";
                    str2 = "空闲最低";
                    str3 = "占用最高";
                    ret = 3;
                }
                else if (AnalogNo == AnalogCodeType.小轨轨入电压)
                {
                    str1 = "调整最高";
                    str2 = "调整最低";
                    str3 = "调整平均";
                    ret = 3;
                }
                else
                {
                    str1 = "最大值";
                    str2 = "最小值";
                    str3 = "平均值";
                    ret = 3;
                }
            }
            return ret;
        }

        #region msggather.ini 判断是否有错误，函数
        /// <summary>
        /// 判断设备类型名称是否正确
        /// </summary>
        /// <param name="TypeName"></param>
        /// <returns></returns>
        static public bool CheckMsgDevTypeIsValid(string TypeName)
        {
            if (TypeName == "电源屏" || TypeName.ToUpper() == "UPS") return true;
            else if (TypeName == "外电网") return true;
            else if (TypeName == "站内轨道电路") return true;
            else if (TypeName == "脉冲轨道电路") return true;
            else if (TypeName == "电码化") return true;
            else if (TypeName == "区间轨道电路") return true;
            else if (TypeName == "转辙机") return true;
            else if (TypeName == "信号机") return true;
            else if (TypeName == "电缆绝缘") return true;
            else if (TypeName == "电源漏流") return true;
            else if (TypeName == "防灾") return true;
            else if (TypeName == "半自动闭塞") return true;
            else if (TypeName == "站联") return true;
            else if (TypeName == "计轴") return true;
            else if (TypeName == "区间监测") return true;
            return false;
        }
        /// <summary>
        /// 判断每种设备类型的属性是否配置准确
        /// </summary>
        /// <param name="TypeName"></param>
        /// <param name="AnalogType"></param>
        /// <returns></returns>
        static public bool CheckMsgDevTypeIncludAnalogType(string TypeName, int AnalogType)
        {
            //还需判断模拟量类型配置是否正确，某种设备类型包含的模拟量，应该是固定的
            AnalogCodeType t = (AnalogCodeType)AnalogType;
            if (TypeName == "电源屏")
            {

            }
            else if(TypeName.ToUpper() == "UPS")
            {
             
            }
            else if (TypeName == "外电网")
            {
             
            }
            else if (TypeName == "站内轨道电路")
            {
             
            }
            else if (TypeName == "脉冲轨道电路")
            {
             
            }
            else if (TypeName == "电码化")
            {
             
            }
            else if (TypeName == "区间轨道电路")
            {
             
            }
            else if (TypeName == "转辙机")
            {
             
            }
            else if (TypeName == "信号机")
            {
             
            }
            else if (TypeName == "电缆绝缘")
            {
             
            }
            else if (TypeName == "电源漏流")
            {
             
            }
            else if (TypeName == "防灾")
            {
             
            }
            else if (TypeName == "半自动闭塞")
            {
            
            }
            else if (TypeName == "站联")
            {
             
            }
            else if (TypeName == "计轴")
            {
             
            }
            else if (TypeName == "区间监测")
            {
             
            }
            if (!IsValidAnalogType(AnalogType)) return false;
            return true;
        }
        /// <summary>
        /// 检查msggather.ini中各个设备对应的模拟量在模拟量配置中是否超过设备编号
        /// </summary>
        /// <param name="TypeName"></param>
        /// <param name="t"></param>
        /// <param name="n"></param>
        /// <returns></returns>
        static public bool CheckDevCfgAnalogNumIsValie(string TypeName, AnalogCodeType t, int n)
        {
            if (n == -1) return true;    //-1相当于没有配置
            if (t == AnalogCodeType.None)
            {
                if (n >= c_Device.KGL_Config.Count) return false;                
            }                
            else if (t == AnalogCodeType.ups)
            {
                if (c_Device.ZH_AnalogConfig.ContainsKey("电源屏"))
                {
                    if(n>= c_Device.ZH_AnalogConfig["电源屏"].AnalogNum) return false;
                }
                else if (c_Device.ZH_AnalogConfig.ContainsKey("电源屏电压"))
                {
                    if (n >= c_Device.ZH_AnalogConfig["电源屏电压"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.ZPW2000A接口信息)
            {
                return false;
            }
            else if (t == AnalogCodeType.半自动闭塞电压和电流)
            {
                if (JC_AnalogConfig.ContainsKey("半自动闭塞"))
                {
                    if (n >= JC_AnalogConfig["半自动闭塞"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.道岔表示电压)
            {
                if (JC_AnalogConfig.ContainsKey("道岔表示电压"))
                {
                    if (n >= JC_AnalogConfig["道岔表示电压"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.道岔缺口)
            {
                if (DCQK_AnlogConfig.ContainsKey("道岔缺口模拟量"))
                {
                    if (n >= DCQK_AnlogConfig["道岔缺口模拟量"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.道床电阻)
            {
                if (YP_AnalogConfig.ContainsKey("道床电阻"))
                {
                    if (n >= YP_AnalogConfig["道床电阻"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.灯丝继电器电流)
            {
                if (JC_AnalogConfig.ContainsKey("灯丝继电器电流"))
                {
                    if (n >= JC_AnalogConfig["灯丝继电器电流"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.灯丝继电器电压)
            {
                if (JC_AnalogConfig.ContainsKey("灯丝继电器电压"))
                {
                    if (n >= JC_AnalogConfig["灯丝继电器电压"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.电缆绝缘)
            {
                if (c_Device.ZH_AnalogConfig.ContainsKey("电缆绝缘"))
                {
                    if (n >= c_Device.ZH_AnalogConfig["电缆绝缘"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.电码化低频)
            {
                if (YP_AnalogConfig.ContainsKey("电码化低频"))
                {
                    if (n >= YP_AnalogConfig["电码化低频"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.电码化发送电流)
            {
                if (YP_AnalogConfig.ContainsKey("电码化发送电流"))
                {
                    if (n >= YP_AnalogConfig["电码化发送电流"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.电码化发送电压)
            {
                if (YP_AnalogConfig.ContainsKey("电码化发送电压"))
                {
                    if (n >= YP_AnalogConfig["电码化发送电压"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.电码化上边频)
            {
                if (YP_AnalogConfig.ContainsKey("电码化上边频"))
                {
                    if (n >= YP_AnalogConfig["电码化上边频"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.电码化下边频)
            {
                if (YP_AnalogConfig.ContainsKey("电码化下边频"))
                {
                    if (n >= YP_AnalogConfig["电码化下边频"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.电码化载频)
            {
                if (YP_AnalogConfig.ContainsKey("电码化载频"))
                {
                    if (n >= YP_AnalogConfig["电码化载频"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.电源漏流)
            {
                if (c_Device.ZH_AnalogConfig.ContainsKey("电源漏流"))
                {
                    if (n >= c_Device.ZH_AnalogConfig["电源漏流"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.电源屏)
            {
                if (c_Device.ZH_AnalogConfig.ContainsKey("电源屏"))
                {
                    if (n >= c_Device.ZH_AnalogConfig["电源屏"].AnalogNum) return false;
                }
                else if (c_Device.ZH_AnalogConfig.ContainsKey("电源屏电压"))
                {
                    if (n >= c_Device.ZH_AnalogConfig["电源屏电压"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.分路残压)
            {
                if (GD_AnalogConfig.ContainsKey("轨道电压"))
                {
                    if (n >= GD_AnalogConfig["轨道电压"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.高压不对称)
            {
                if (GD_AnalogConfig.ContainsKey("高压不对称"))
                {
                    if (n >= GD_AnalogConfig["高压不对称"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.轨出1低频)
            {
                if (YP_AnalogConfig.ContainsKey("轨出1低频"))
                {
                    if (n >= YP_AnalogConfig["轨出1低频"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.轨出1电压 || t == AnalogCodeType.轨出1分路残压)
            {
                if (YP_AnalogConfig.ContainsKey("轨出1电压"))
                {
                    if (n >= YP_AnalogConfig["轨出1电压"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.轨出1上边频)
            {
                if (YP_AnalogConfig.ContainsKey("轨出1上边频"))
                {
                    if (n >= YP_AnalogConfig["轨出1上边频"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.轨出1下边频)
            {
                if (YP_AnalogConfig.ContainsKey("轨出1下边频"))
                {
                    if (n >= YP_AnalogConfig["轨出1下边频"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.轨出1载频)
            {
                if (YP_AnalogConfig.ContainsKey("轨出1载频"))
                {
                    if (n >= YP_AnalogConfig["轨出1载频"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.轨出2低频)
            {
                if (YP_AnalogConfig.ContainsKey("轨出2低频"))
                {
                    if (n >= YP_AnalogConfig["轨出2低频"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.轨出2电压)
            {
                if (YP_AnalogConfig.ContainsKey("轨出2电压"))
                {
                    if (n >= YP_AnalogConfig["轨出2电压"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.轨出2载频)
            {
                if (YP_AnalogConfig.ContainsKey("轨出2载频"))
                {
                    if (n >= YP_AnalogConfig["轨出2载频"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.轨道编码)
            {
                if (YP_AnalogConfig.ContainsKey("轨道编码"))
                {
                    if (n >= YP_AnalogConfig["轨道编码"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.轨道电流)
            {
                if (YP_AnalogConfig.ContainsKey("轨道电流"))
                {
                    if (n >= YP_AnalogConfig["轨道电流"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.轨道电压)
            {
                if (YP_AnalogConfig.ContainsKey("轨道电压"))
                {
                    if (n >= YP_AnalogConfig["轨道电压"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.轨道相位角)
            {
                if (YP_AnalogConfig.ContainsKey("轨道相位角"))
                {
                    if (n >= YP_AnalogConfig["轨道相位角"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.轨道直流电压)
            {
                if (YP_AnalogConfig.ContainsKey("轨道直流电压"))
                {
                    if (n >= YP_AnalogConfig["轨道直流电压"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.环境模拟量)
            {
                if (HK_AnlogConfig.ContainsKey("环境模拟量"))
                {
                    if (n >= HK_AnlogConfig["环境模拟量"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.计轴)
            {
                if (GD_AnalogConfig.ContainsKey("计轴"))
                {
                    if (n >= GD_AnalogConfig["计轴"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.空调参数)
            {
                if (HK_AnlogConfig.ContainsKey("空调控制"))
                {
                    if (n >= HK_AnlogConfig["空调控制"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.牵引电流干扰电压)
            {
                if (GD_AnalogConfig.ContainsKey("牵引电流干扰电压"))
                {
                    if (n >= GD_AnalogConfig["牵引电流干扰电压"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.区间室外监测)
            {
                if (JC_AnalogConfig.ContainsKey("区间室外监测"))
                {
                    if (n >= JC_AnalogConfig["区间室外监测"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.外电网)
            {
                if (c_Device.ZH_AnalogConfig.ContainsKey("外电网"))
                {
                    if (n >= c_Device.ZH_AnalogConfig["外电网"].AnalogNum) return false;
                }
                else if (c_Device.ZH_AnalogConfig.ContainsKey("外电网监测"))
                {
                    if (n >= c_Device.ZH_AnalogConfig["外电网监测"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.小轨轨入电压)
            {
                if (YP_AnalogConfig.ContainsKey("小轨轨入电压"))
                {
                    if (n >= YP_AnalogConfig["小轨轨入电压"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.移频发送电缆侧电流)
            {
                if (YP_AnalogConfig.ContainsKey("移频发送电缆侧电流"))
                {
                    if (n >= YP_AnalogConfig["移频发送电缆侧电流"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.移频发送电缆侧电压)
            {
                if (YP_AnalogConfig.ContainsKey("移频发送电缆侧电压"))
                {
                    if (n >= YP_AnalogConfig["移频发送电缆侧电压"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.移频发送器低频)
            {
                if (YP_AnalogConfig.ContainsKey("移频发送器低频"))
                {
                    if (n >= YP_AnalogConfig["移频发送器低频"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.移频发送器发送电流)
            {
                if (YP_AnalogConfig.ContainsKey("移频发送器发送电流"))
                {
                    if (n >= YP_AnalogConfig["移频发送器发送电流"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.移频发送器发送电压)
            {
                if (YP_AnalogConfig.ContainsKey("移频发送器发送电压"))
                {
                    if (n >= YP_AnalogConfig["移频发送器发送电压"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.移频发送器载频)
            {
                if (YP_AnalogConfig.ContainsKey("移频发送器载频"))
                {
                    if (n >= YP_AnalogConfig["移频发送器载频"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.移频接收电缆侧电压)
            {
                if (YP_AnalogConfig.ContainsKey("移频接收电缆侧电压"))
                {
                    if (n >= YP_AnalogConfig["移频接收电缆侧电压"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.异物继电器端电压)
            {
                if (JC_AnalogConfig.ContainsKey("异物继电器端电压"))
                {
                    if (n >= JC_AnalogConfig["异物继电器端电压"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.站联电压)
            {
                if (JC_AnalogConfig.ContainsKey("站联电压"))
                {
                    if (n >= JC_AnalogConfig["站联电压"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.主轨轨入低频)
            {
                if (YP_AnalogConfig.ContainsKey("主轨轨入低频"))
                {
                    if (n >= YP_AnalogConfig["主轨轨入低频"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.主轨轨入电压)
            {
                if (YP_AnalogConfig.ContainsKey("主轨轨入电压"))
                {
                    if (n >= YP_AnalogConfig["主轨轨入电压"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.主轨轨入载频)
            {
                if (YP_AnalogConfig.ContainsKey("主轨轨入载频"))
                {
                    if (n >= YP_AnalogConfig["主轨轨入载频"].AnalogNum) return false;
                }
                else return false;
            }
            else if (t == AnalogCodeType.转辙机功率)
            {
                return false;
            }
            return true;
        }
        #endregion

        static public void StopAllThread()
        {
            c_NetCom.Stop_Thread_DisposeNetData();
            MySql.c.StopPoolThread();
            C_MyPipe.StopPipeThread();
            c_NetCom.TcpConnect.StopTcpIpRevThread();
        }

    }

    public class objSysCfg
    {
        public int TerminalFlag = -1;
        public string TelexCode = "";
        public byte[] TelexCodeB = new byte[3];
        public string SevTelexCode="";
        public byte[] SevTelexCodeB = new byte[3];
        public string SevIpAddress = "";
        public int SevPort = 0;
    }

    public static class c_Config
    {
        public static objSysCfg sysConfig = new objSysCfg();
    }

    public class INIFile
    {
        //声明读写INI文件的API函数 
        [DllImport("kernel32")]
        private static extern bool WritePrivateProfileString(string section, string key, string val, string filePath);
        [DllImport("kernel32")]
        private static extern int GetPrivateProfileString(string section, string key, string def, byte[] retVal, int size, string filePath);
        [DllImport("kernel32")]
        private static extern int GetPrivateProfileSection(string section, byte[] retVal, int size, string filePath);
        [DllImport("kernel32")]
        private static extern int WritePrivateProfileSection(string section, string val, string filePath);
        [DllImport("kernel32")]
        private static extern int GetPrivateProfileSectionNames(byte[] retVal, uint size, string filePath);
        [DllImport("kernel32")]
        private static extern uint GetPrivateProfileInt(string section, string key, int val, string filePath);

        public String replaceBlank(String str)
        {
            String result = str;
            if (str != null)
            {
                result = Regex.Replace(result, @"\s*|\t|\r|\n", "", RegexOptions.IgnoreCase);
                result = Regex.Replace(result, "（", "(", RegexOptions.IgnoreCase);
                result = Regex.Replace(result, "）", ")", RegexOptions.IgnoreCase);
            }
            return result;
        }

        private int ConvertHexStringToInt(string HexString)
        {
            int retVal = -1;
            if (HexString.Length > 0)
            {
                HexString.Trim();
                int ks = HexString.IndexOf("0x");
                HexString = HexString.Substring(ks + 2); //去除前方的0x
                
                if (HexString.Length > 0)
                {
                    try
                    {
                        retVal = Convert.ToInt32(HexString, 16);
                    }
                    catch
                    {
                        retVal = -1;
                    }
                }
            }
            return retVal;
        }

        private void ReadAnalogList(string s_SecName, string lpFileName, ref objAnalogTypeStruct TmpAnalogCFG)
        {
            string s_KeyName = "变化范围";
            byte[] retVal = new byte[255];
            int charlen = GetPrivateProfileString(s_SecName, s_KeyName, null, retVal, 255, lpFileName);
            if (charlen > 0)
            {
                string sp = System.Text.Encoding.Default.GetString(retVal,0,charlen).Trim('\0');
                string[] sp1 = new string[2];
                sp1 = sp.Split(',');
                TmpAnalogCFG.SpanA = float.Parse(sp1[0].Trim('\0'));
                int k1 = sp1[1].IndexOf('\0');
                if (k1 > 0) TmpAnalogCFG.SpanB = float.Parse(sp1[1].Substring(0, k1));
                else TmpAnalogCFG.SpanB = float.Parse(sp1[1]);
            }

            s_KeyName = "总路数";
            TmpAnalogCFG.AnalogNum = (int)GetPrivateProfileInt(s_SecName, s_KeyName, 0, lpFileName);
            s_KeyName = "开始AD号";
            TmpAnalogCFG.StartADNo = (int)GetPrivateProfileInt(s_SecName, s_KeyName, 0, lpFileName);
            for (int k = 1; k <= TmpAnalogCFG.AnalogNum; k++)
            {
                objSingleAnalogStruct TmpAnalogObj = new objSingleAnalogStruct();
                string No = k.ToString();
                s_KeyName = No;
                byte[] retValue = new byte[1024 * 2];
                int retlen = GetPrivateProfileString(s_SecName, s_KeyName, null, retValue, 1024 * 2, lpFileName);
                string sretVal = System.Text.Encoding.Default.GetString(retValue,0,retlen).Trim();
                string[] sp_sret = new string[16];
                sp_sret = sretVal.Split(',');                
                TmpAnalogObj.AnalogName = sp_sret[0].Trim();
                TmpAnalogObj.Flag = short.Parse(sp_sret[1].Trim());
                TmpAnalogObj.ADNumber = short.Parse(sp_sret[2].Trim());
                TmpAnalogObj.DisplayNumber = short.Parse(sp_sret[3].Trim());
                TmpAnalogObj.ADMin = float.Parse(sp_sret[4].Trim());
                TmpAnalogObj.ADMax = float.Parse(sp_sret[5].Trim());
                TmpAnalogObj.ADCoeff = float.Parse(sp_sret[6].Trim());
                TmpAnalogObj.UpperThreshold = float.Parse(sp_sret[7].Trim());
                TmpAnalogObj.LowerThreshold = float.Parse(sp_sret[8].Trim());
                TmpAnalogObj.FLUpperThreshold = float.Parse(sp_sret[9].Trim());
                TmpAnalogObj.FenJiNo = short.Parse(sp_sret[10].Trim());
                TmpAnalogObj.UnitName = sp_sret[11].Trim();
                TmpAnalogObj.UnitName = TmpAnalogObj.UnitName.Trim('\t');
                int m = sp_sret.Length;
                if (m > 12)
                {
                    TmpAnalogObj.YLFlag1 = float.Parse(sp_sret[12].Trim());
                    TmpAnalogObj.YLFlag2 = float.Parse(sp_sret[13].Trim());
                    TmpAnalogObj.YLFlag3 = float.Parse(sp_sret[14].Trim());
                    TmpAnalogObj.YLFlag4 = float.Parse(sp_sret[15].Trim());
                }
                TmpAnalogCFG.AnalogList.Add(TmpAnalogObj);
            }
        }

        public void Read_DC_INI(string lpFileName)
        {
            if (lpFileName != "")
            {
                string SecName = "模拟量项目";
                string KeyName = "子项数目";
                uint analogTypeNum = 0;
                analogTypeNum = GetPrivateProfileInt(SecName, KeyName, 0, lpFileName);
                for (int i = 1; i <= analogTypeNum; i++)
                {
                    string s_SecName = "子项" + i.ToString();
                    string s_KeyName = "名称";
                    byte [] retVal = new byte [255];
                    int retlen = GetPrivateProfileString(s_SecName, s_KeyName, null, retVal, 255, lpFileName);
                    string sdickey = System.Text.Encoding.Default.GetString(retVal,0,retlen).Trim('\0');
                    objAnalogTypeStruct TmpAnalogCFG = new objAnalogTypeStruct();
                    if (sdickey == "道岔动作电流" || sdickey == "道岔油压" || sdickey == "道岔拉力")
                    {
                        ReadAnalogList(s_SecName, lpFileName, ref TmpAnalogCFG);
                        c_Device.DC_AnalogConfig.Add(sdickey, TmpAnalogCFG);
                    }
                }
            }
        }

        public void Read_GD_INI(string lpFileName)
        {
            if (lpFileName != "")
            {
                string SecName = "模拟量项目";
                string KeyName = "子项数目";
                uint analogTypeNum = 0;
                analogTypeNum = GetPrivateProfileInt(SecName, KeyName, 0, lpFileName);
                for (int i = 1; i <= analogTypeNum; i++)
                {
                    string s_SecName = "子项" + i.ToString();
                    string s_KeyName = "名称";
                    byte[] retVal = new byte[255];
                    int retlen = GetPrivateProfileString(s_SecName, s_KeyName, null, retVal, 255, lpFileName);
                    string sdickey = System.Text.Encoding.Default.GetString(retVal,0,retlen).Trim('\0');
                   
                    objAnalogTypeStruct TmpAnalogCFG = new objAnalogTypeStruct();
                    if (sdickey == "轨道电压" || sdickey == "轨道相位角" || sdickey == "轨道电流" || sdickey == "高压不对称"
                        || sdickey == "高压不对称电压波形" || sdickey == "牵引电流干扰电压" || sdickey == "计轴")
                    {
                        ReadAnalogList(s_SecName, lpFileName, ref TmpAnalogCFG);
                        c_Device.GD_AnalogConfig.Add(sdickey, TmpAnalogCFG);
                        if (TmpAnalogCFG.AnalogNum > 0)
                        {
                            if (sdickey == "轨道电压" || sdickey == "轨道相位角" || sdickey == "轨道电流" || sdickey == "高压不对称"
                                || sdickey == "牵引电流干扰电压" || sdickey == "计轴")
                            {
                                objConfigAnalog obj = new objConfigAnalog();
                                obj.IniFileName = "gd";
                                obj.TypeName = sdickey;
                                obj.type = c_Device.GetAnalogTypeFromName(sdickey);
                                c_Device.AnalogcCollocation.Add(obj);
                            }
                        }
                    }
                }
            }
        }

        public void Read_JC_INI(string lpFileName)
        {
            if (lpFileName != "")
            {
                string SecName = "模拟量项目";
                string KeyName = "子项数目";
                uint analogTypeNum = 0;
                analogTypeNum = GetPrivateProfileInt(SecName, KeyName, 0, lpFileName);
                for (int i = 1; i <= analogTypeNum; i++)
                {
                    string s_SecName = "子项" + i.ToString();
                    string s_KeyName = "名称";
                    byte[] retVal = new byte[255];
                    int retlen = GetPrivateProfileString(s_SecName, s_KeyName, null, retVal, 255, lpFileName);
                    string sdickey = System.Text.Encoding.Default.GetString(retVal,0,retlen).Trim('\0');

                    objAnalogTypeStruct TmpAnalogCFG = new objAnalogTypeStruct();
                    if (sdickey == "灯丝继电器电流" || sdickey == "道岔表示电压" || sdickey == "灯丝继电器电压" || sdickey == "半自动闭塞电压和电流"
                        || sdickey == "异物继电器端电压" || sdickey == "站联电压" || sdickey == "区间室外监测")
                    {
                        
                        
                        ReadAnalogList(s_SecName, lpFileName, ref TmpAnalogCFG);
                        c_Device.JC_AnalogConfig.Add(sdickey, TmpAnalogCFG);
                        if(TmpAnalogCFG.AnalogNum>0)
                        {
                            objConfigAnalog obj = new objConfigAnalog();
                            obj.IniFileName = "jc";
                            obj.TypeName = sdickey;
                            obj.type = c_Device.GetAnalogTypeFromName(sdickey);
                            if (sdickey == "半自动闭塞电压和电流")
                            {
                                //半自闭是高频模拟量，不在普通模拟量表里面
                            }
                            else c_Device.AnalogcCollocation.Add(obj);
                        }
                    }
                }
            }
        }

        public void Read_ZH_INI(string lpFileName)
        {
            if (lpFileName != "")
            {
                string SecName = "模拟量项目";
                string KeyName = "子项数目";
                uint analogTypeNum = 0;
                analogTypeNum = GetPrivateProfileInt(SecName, KeyName, 0, lpFileName);
                for (int i = 1; i <= analogTypeNum; i++)
                {
                    string s_SecName = "子项" + i.ToString();
                    string s_KeyName = "名称";
                    byte[] retVal = new byte[255];
                    int retlen = GetPrivateProfileString(s_SecName, s_KeyName, null, retVal, 255, lpFileName);
                    string sdickey = System.Text.Encoding.Default.GetString(retVal,0,retlen).Trim('\0');
                    if (sdickey == "电源屏电压" || sdickey == "电源屏" || sdickey == "电缆绝缘" || sdickey == "电源漏流" || sdickey == "外电网监测" || sdickey == "外电网")
                    {
                        
                    }
                    objAnalogTypeStruct TmpAnalogCFG = new objAnalogTypeStruct();
                    if (sdickey == "电源屏电压" || sdickey == "电源屏" || sdickey == "电缆绝缘" || sdickey == "电源漏流" || sdickey == "外电网监测" || sdickey == "外电网")
                    {
                        ReadAnalogList(s_SecName, lpFileName, ref TmpAnalogCFG);
                        c_Device.ZH_AnalogConfig.Add(sdickey, TmpAnalogCFG);
                        if(TmpAnalogCFG.AnalogNum>0)
                        {
                            objConfigAnalog obj = new objConfigAnalog();
                            obj.IniFileName = "zh";
                            obj.TypeName = sdickey;
                            string s = sdickey;
                            if (s == "电源屏电压") s = "电源屏";
                            else if (s == "外电网监测") s = "外电网";
                            obj.type = c_Device.GetAnalogTypeFromName(s);
                            c_Device.AnalogcCollocation.Add(obj);
                        }
                    }
                }
            }
        }

        public void Read_YP_INI(string lpFileName)
        {
            if (lpFileName != "")
            {
                string SecName = "模拟量项目";
                string KeyName = "子项数目";
                uint analogTypeNum = 0;
                analogTypeNum = GetPrivateProfileInt(SecName, KeyName, 0, lpFileName);
                for (int i = 1; i <= analogTypeNum; i++)
                {
                    string s_SecName = "子项" + i.ToString();
                    string s_KeyName = "名称";
                    byte[] retVal = new byte[255];
                    int retlen = GetPrivateProfileString(s_SecName, s_KeyName, null, retVal, 255, lpFileName);
                    string sdickey = System.Text.Encoding.Default.GetString(retVal,0,retlen).Trim('\0');
                    
                    objAnalogTypeStruct TmpAnalogCFG = new objAnalogTypeStruct();
                    if (sdickey == "电码化发送电压" || sdickey == "电码化发送电流" || sdickey == "移频发送器发送电压" || sdickey == "主轨轨入电压"
                        || sdickey == "移频发送器发送电流" || sdickey == "移频发送电缆侧电压" || sdickey == "移频接收电缆侧电压" || sdickey == "电码化载频"
                        || sdickey == "电码化低频" || sdickey == "移频发送器载频" || sdickey == "移频发送器低频" || sdickey == "轨出1载频"
                        || sdickey == "轨出1低频" || sdickey == "轨出2载频" || sdickey == "轨出2低频" || sdickey == "电码化上边频" || sdickey == "小轨轨入电压"
                        || sdickey == "电码化下边频" || sdickey == "主轨轨入载频" || sdickey == "主轨轨入低频" || sdickey == "轨出1上边频"
                        || sdickey == "轨出1下边频" || sdickey == "移频发送电缆侧电流" || sdickey == "道床电阻" || sdickey == "轨出1电压" || sdickey == "轨出2电压")
                    {
                        ReadAnalogList(s_SecName, lpFileName, ref TmpAnalogCFG);
                        c_Device.YP_AnalogConfig.Add(sdickey, TmpAnalogCFG);
                        if(TmpAnalogCFG.AnalogNum>0)
                        {
                            objConfigAnalog obj = new objConfigAnalog();
                            obj.IniFileName = "yp";
                            obj.TypeName = sdickey;
                            obj.type = c_Device.GetAnalogTypeFromName(sdickey);
                            c_Device.AnalogcCollocation.Add(obj);
                        }
                    }
                }
            }
        }

        public void Read_XHJ_INI(string lpFileName)
        {
            if (lpFileName != null)
            {
                string SecName = "灯丝";
                string KeyName = "总路数";
                c_Device.XHJ_DSAlarmConfig.DS_ALLNum = (int)GetPrivateProfileInt(SecName, KeyName, 0, lpFileName);
                KeyName = "信息来源采集机";
                c_Device.XHJ_DSAlarmConfig.CJJ_Inf = (int)GetPrivateProfileInt(SecName, KeyName, 0, lpFileName);
                KeyName = "信息来源伯瑞特";
                c_Device.XHJ_DSAlarmConfig.BRT_Inf = (int)GetPrivateProfileInt(SecName, KeyName, 0, lpFileName);
                KeyName = "伯瑞特开始序号";
                c_Device.XHJ_DSAlarmConfig.BRT_StartNo = (int)GetPrivateProfileInt(SecName, KeyName, 0, lpFileName);
                KeyName = "伯瑞特总路数";
                c_Device.XHJ_DSAlarmConfig.BRT_ALLNum = (int)GetPrivateProfileInt(SecName, KeyName, 0, lpFileName);

                for (int i = 1; i <= c_Device.XHJ_DSAlarmConfig.DS_ALLNum;i++ )
                {
                    KeyName = i.ToString();
                    byte[] retVal = new byte[255];
                    int retlen = GetPrivateProfileString(SecName, KeyName, null, retVal, 255, lpFileName);
                    string sLine = System.Text.Encoding.Default.GetString(retVal,0,retlen).Trim('\0');
                    string[] sp = new string[4];
                    sp = sLine.Split(',');
                    objDS_Struct ds = new objDS_Struct();
                    ds.DS_Name = sp[0].Trim();
                    ds.ThroatNumber = int.Parse(sp[1].Trim());
                    ds.Code = int.Parse(sp[2].Trim());
                    sp[3].Trim();
                    int k1 = sp[3].IndexOf('\0');
                    if(k1>0) ds.FenJiNo = int.Parse(sp[3].Substring(0,k1));
                    else ds.FenJiNo = int.Parse(sp[3]);
                    c_Device.XHJ_DSAlarmConfig.ValueList.Add(ds);
                }
            }
        }
        #region 列控读取
        private void lk_Read_HLInfo(string lpFileName)
        {
            if (lpFileName != null)
            {
                string SecName = "列控互联信息配置";
                string KeyName = "总数";

                int len = (int)GetPrivateProfileInt(SecName, KeyName, 0, lpFileName);
                for (int i = 1; i <= len; i++)
                {
                    KeyName = i.ToString();
                    byte[] retVal = new byte[1024];
                    int retLen = GetPrivateProfileString(SecName, KeyName, null, retVal, 1024, lpFileName);
                    if (retLen > 0)
                    {
                        lkHLPZ TmpHL = new lkHLPZ();
                        string sLine = System.Text.Encoding.Default.GetString(retVal,0,retLen).Trim();
                        string[] sp = new string[3];
                        try
                        {
                            sp = sLine.Split(',', '，');
                            string tmpSring = sp[0].Trim();
                            TmpHL.Name = tmpSring;
                            tmpSring = sp[1].Trim();
                            TmpHL.TypeCode = int.Parse(tmpSring);
                            tmpSring = sp[2].Trim();
                            int h = ConvertHexStringToInt(tmpSring);
                            if (h != -1) TmpHL.ProtolCode = h;
                            else
                            {
                                MessageBox.Show(string.Format("列控互联信息配置，第{0}行错误", i));
                                return;
                            }
                        }
                        catch
                        {
                            MessageBox.Show(string.Format("列控互联信息配置，第{0}行错误", i));
                            return;
                        }
                        c_Device.LK1_Config.HL_InfoList.Add(TmpHL);
                    }
                }                
            }
        }

        private void lk_Read_YJPTInfo(string lpFileName)
        {
            if (lpFileName != null)
            {
                string SecName = "列控中心主机硬件平台";
                string KeyName = "上送列数";
                int k = (int)GetPrivateProfileInt(SecName, KeyName, 0, lpFileName);
                KeyName = "上送列信息";
                byte[] retVal = new byte[1024];
                int retLen = GetPrivateProfileString(SecName, KeyName, null, retVal, 1024, lpFileName);
                string sLine = System.Text.Encoding.Default.GetString(retVal,0,retLen).Trim();
                string[] sp = sLine.Split(',','，');
                if (sp.Length != k)
                {
                    MessageBox.Show("列控中心主机硬件平台 上送列信息 配置错误");
                    return;
                }
                for (int i = 0; i < sp.Length; i++)
                {
                    string tmp = sp[i].Trim();
                    tmp.Trim('\0');
                    c_Device.LK1_Config.ZhuJiYjpt_SendColName.Add(tmp);
                }
                KeyName = "总数";
                int len = (int)GetPrivateProfileInt(SecName, KeyName, 0, lpFileName);
                for (int i = 1; i <= len; i++)
                {
                    byte[] retString = new byte[1024];
                    KeyName = i.ToString();
                    retLen = GetPrivateProfileString(SecName, KeyName, null, retString, 1024, lpFileName);
                    sLine = System.Text.Encoding.Default.GetString(retString, 0, retLen).Trim();
                    sp = sLine.Split(',', '，');
                    if (sp.Length != 2)
                    {
                        MessageBox.Show(string.Format("列控中心主机硬件平台 第{0}行 配置错误",i));
                        return;
                    }
                    lkZJYJPT_PZ tmpZJYJPT = new lkZJYJPT_PZ();
                    string tmp = sp[0].Trim();
                    tmp = replaceBlank(sp[0]);                    
                    tmpZJYJPT.SehBeiTypeName = tmp;
                    tmp = sp[1].Trim();
                    tmp = replaceBlank(sp[1]);
                    tmpZJYJPT.SheBeiName = tmp;

                    c_Device.LK1_Config.ZhuJiYjpt_SheBeiList.Add(tmpZJYJPT);
                }
            }
        }

        private void lk_Read_SameInfo(string SecName, string lpFileName)
        {
            if (lpFileName != null)
            {
                string KeyName = "上送列数";
                int t = (int)GetPrivateProfileInt(SecName, KeyName, 0, lpFileName);
                KeyName = "上送列信息";
                byte[] retString = new byte[1024];
                int retLen = GetPrivateProfileString(SecName, KeyName, null, retString, 1024, lpFileName);
                if (retLen > 0)
                {
                    string sLine = System.Text.Encoding.Default.GetString(retString,0,retLen).Trim();
                    string[] sp = sLine.Split(',', '，');
                    if (t != sp.Length)
                    {
                        MessageBox.Show(string.Format("{0},{1}配置错误", SecName, KeyName));
                        return;
                    }
                    for (int i = 0; i < t; i++)
                    {
                        string tmpString = sp[i].Trim();
                        tmpString.Trim('\0');
                        if (SecName == "列控中心与联锁接口进路信息") c_Device.LK1_Config.LianSuo_RouteInfo.Add(tmpString);
                        else if (SecName == "列控中心与联锁改方命令信息") c_Device.LK1_Config.LianSuo_GaiFangCommandInfo.Add(tmpString);
                        else if (SecName == "列控中心与联锁改方回执信息") c_Device.LK1_Config.LianSuo_GaiFangCommRetInfo.Add(tmpString);
                        else if (SecName == "列控中心站间改方命令信息") c_Device.LK1_Config.ZhangJian_GaiFangCommandInfo.Add(tmpString);
                        else if (SecName == "列控中心站间改方回执信息") c_Device.LK1_Config.ZhangJian_GaiFangCommRetInfo.Add(tmpString);
                        else if (SecName == "列控中心站间边界信息") c_Device.LK1_Config.ZhangJian_BianJieInfo.Add(tmpString);
                        else if (SecName == "发送给联锁的无配线站区间方向口信息") c_Device.LK1_Config.SendToLianSuoInfo.Add(tmpString);
                        else if (SecName == "列控中心临时限速状态") c_Device.LK1_Config.LinShiLimitSpeedInfo.Add(tmpString);
                        else if (SecName == "应答器报文编码信息") c_Device.LK1_Config.BTM_CodeInfo.Add(tmpString);
                    }
                }
            }
        }

        private void lk_Read_SectionCodeInfo(string lpFileName)
        {
            if (lpFileName != null)
            {
                string SecName = "轨道区段编码信息";
                string KeyName = "上送列数";
                int k = (int)GetPrivateProfileInt(SecName, KeyName, 0, lpFileName);
                KeyName = "上送列信息";
                byte[] retVal = new byte[1024];
                int retLen = GetPrivateProfileString(SecName, KeyName, null, retVal, 1024, lpFileName);
                string sLine = System.Text.Encoding.Default.GetString(retVal,0,retLen).Trim();
                string[] sp = sLine.Split(',', '，');
                if (sp.Length != k)
                {
                    MessageBox.Show("轨道区段编码信息 上送列信息 配置错误");
                    return;
                }
                for (int i = 0; i < sp.Length; i++)
                {
                    string tmp = sp[i].Trim();
                    tmp.Trim("\\0".ToCharArray());
                    c_Device.LK1_Config.Section_SendColList.Add(tmp);
                }
                KeyName = "总数";
                int len = (int)GetPrivateProfileInt(SecName, KeyName, 0, lpFileName);
                for (int i = 1; i <= len; i++)
                {
                    retVal.Initialize();
                    KeyName = i.ToString();
                    byte[] retString = new byte[1024];
                    retLen = GetPrivateProfileString(SecName, KeyName, null, retString, 1024, lpFileName);
                    sLine = System.Text.Encoding.Default.GetString(retString,0,retLen).Trim();
                    sp = sLine.Split(',', '，');
                    if (sp.Length != 3)
                    {
                        MessageBox.Show(string.Format("轨道区段编码信息 第{0}行 配置错误", i));
                        return;
                    }
                    lkSectionCode tmpSectionCode = new lkSectionCode();
                    string tmp = sp[0].Trim();
                    tmp.Trim('\0');
                    tmpSectionCode.SectionName = tmp;
                    tmp = sp[1].Trim();
                    tmp.Trim('\0');
                    tmpSectionCode.JiGui_ID = int.Parse(tmp);
                    tmp = sp[2].Trim();
                    tmp.Trim('\0');
                    tmpSectionCode.AtJiGuiNo = int.Parse(tmp);
                    c_Device.LK1_Config.SectionCodeInfo.Add(tmpSectionCode);
                }
            }
        }

        private void lk_Read_SameOneColInfor(string SecName, string KeyName, string lpFileName)
        {
            if (lpFileName != null)
            {
                int t = (int)GetPrivateProfileInt(SecName, KeyName, 0, lpFileName);
                for (int i = 1; i <= t; i++)
                {
                    KeyName = i.ToString();
                    byte[] retVal = new byte[1024];
                    int retlen = GetPrivateProfileString(SecName, KeyName, null, retVal, 1024, lpFileName);
                    if (retlen > 0)
                    {
                        string TmpString = System.Text.Encoding.Default.GetString(retVal,0,retlen).Trim();
                        TmpString.Trim();
                        TmpString.Trim('\0');
                        if (SecName == "主板") c_Device.LK1_Config.ZhuBan_Info.Add(TmpString);
                        else if (SecName == "周边故障状态") c_Device.LK1_Config.ZhouBian_ErrorInfo.Add(TmpString);
                        else if (SecName == "System情报区") c_Device.LK1_Config.System_Info.Add(TmpString);
                        else if (SecName == "PIO机笼接口") c_Device.LK1_Config.PIO_Info.Add(TmpString);
                        else if (SecName == "LEU切换单元状态") c_Device.LK1_Config.LEU_Info.Add(TmpString);
                        else if (SecName == "CTC/TSRS初始化") c_Device.LK1_Config.CTC_TSRS.Add(TmpString);
                        else if (SecName == "TCC机柜CAN通信") c_Device.LK1_Config.TCC_CAN.Add(TmpString);
                        else if (SecName == "TCC与联锁通道") c_Device.LK1_Config.TCC_LianSuo.Add(TmpString);
                        else if (SecName == "TCC与TSRS通道") c_Device.LK1_Config.TCC_TSRS.Add(TmpString);
                        else if (SecName == "TCC与车站通道") c_Device.LK1_Config.TCC_CheZhan.Add(TmpString);
                        else if (SecName == "TCC与联锁机系") c_Device.LK1_Config.TCC_LianSuoJiXi.Add(TmpString);
                        else if (SecName == "TCC与TSRS机系") c_Device.LK1_Config.TCC_TSRS_JiXi.Add(TmpString);
                        else if (SecName == "TCC与车站机系") c_Device.LK1_Config.TCC_CheZhanJiXi.Add(TmpString);
                        else if (SecName == "TCC与CIGS板") c_Device.LK1_Config.TCC_CIGS.Add(TmpString);
                        else if (SecName == "LEU通道") c_Device.LK1_Config.LEU_TongDao.Add(TmpString);
                        else if (SecName == "LEU端口") c_Device.LK1_Config.LEU_DuanKou.Add(TmpString);
                        else if (SecName == "区间信号机名称") c_Device.LK1_Config.QuJianSignalName.Add(TmpString);
                        else if (SecName == "区间线路名称") c_Device.LK1_Config.QuJianXianLuName.Add(TmpString);
                        else if (SecName == "列控邻站名称") c_Device.LK1_Config.LinZhanName.Add(TmpString);
                        else if (SecName == "PIO驱动继电器名称") c_Device.LK1_Config.PIO_QuDongName.Add(TmpString);
                        else if (SecName == "PIO采集继电器名称") c_Device.LK1_Config.PIO_CaiJiName.Add(TmpString);
                        else if (SecName == "灾害继电器名称") c_Device.LK1_Config.ZaiHai_Name.Add(TmpString);
                        else if (SecName == "状态信息轨道名称") c_Device.LK1_Config.ZhuangTai_SectionName.Add(TmpString);
                    }
                }
            }
        }

        private void lk_Read_LianSuoRouteInfo(string lpFileName)
        {
            if (lpFileName != null)
            {
                string SecName = "进路信息";
                string KeyName = "总路数";
                int t = (int)GetPrivateProfileInt(SecName, KeyName, 0, lpFileName);
                for (int i = 1; i <= t; i++)
                {
                    KeyName = i.ToString();
                    byte[] retVal = new byte[1024];
                    int l = GetPrivateProfileString(SecName, KeyName, null, retVal, 1024, lpFileName);
                    string sLine = System.Text.Encoding.Default.GetString(retVal,0,l).Trim();
                    string[] sp = new string[256];
                    sp = sLine.Split(',');
                    int len = sp.Length;
                    lkRouteInfo Lk = new lkRouteInfo();
                    Lk.LSNumber = int.Parse(sp[0].Trim());
                    Lk.LKNumber = int.Parse(sp[1].Trim());
                    Lk.LKNumber_16 = sp[2].Trim();
                    Lk.JLNmae = sp[3].Trim();
                    Lk.QDNumber = int.Parse(sp[4].Trim());
                    Lk.JLType = sp[5].Trim();
                    Lk.StartXhjName = sp[6].Trim();
                    Lk.EndXhjName = sp[7].Trim();
                    int secNum = len - 8;
                    for (int k = 0; k < secNum; k++)
                    {
                        string sectionName = sp[k + 7].Trim();
                        Lk.QD_List.Add(sectionName);
                    }
                    c_Device.LK1_Config.RouteInfo.Add(Lk);
                }
            }
        }

        public void Read_LK1_INI(string lpFileName)
        {
            if (lpFileName != null)
            {
                string SecName = "列控通信协议配置";
                string KeyName = "厂家类型";
                byte[] retVal = new byte[256];
                int retLen = GetPrivateProfileString(SecName, KeyName, null, retVal, 256, lpFileName);
                if (retLen > 0)
                {
                    string TmpString = System.Text.Encoding.Default.GetString(retVal,0,retLen);
                    TmpString.Trim();
                    TmpString.Trim('\0');
                    int len = TmpString.Length;
                    c_Device.LK1_Config.CorpName = TmpString;
                }
                else
                {
                    Console.WriteLine("没有配置列控厂家信息");
                    //MessageBox.Show("没有配置列控厂家信息");
                }
                lk_Read_HLInfo(lpFileName);     //读列控互联信息配置
                lk_Read_YJPTInfo(lpFileName);   //读列控中心主机硬件平台
                lk_Read_SameInfo("列控中心与联锁接口进路信息", lpFileName);
                lk_Read_SameInfo("列控中心与联锁改方命令信息", lpFileName);
                lk_Read_SameInfo("列控中心与联锁改方回执信息", lpFileName);
                lk_Read_SameInfo("列控中心站间改方命令信息", lpFileName);
                lk_Read_SameInfo("列控中心站间改方回执信息",lpFileName);
                lk_Read_SameInfo("列控中心站间边界信息", lpFileName);
                lk_Read_SameInfo("发送给联锁的无配线站区间方向口信息", lpFileName);
                lk_Read_SameInfo("列控中心临时限速状态", lpFileName);
                lk_Read_SameInfo("应答器报文编码信息", lpFileName);
                lk_Read_SectionCodeInfo(lpFileName);
                lk_Read_SameOneColInfor("主板", "数量", lpFileName);
                lk_Read_SameOneColInfor("周边故障状态", "数量", lpFileName);
                lk_Read_SameOneColInfor("System情报区", "数量", lpFileName);
                lk_Read_SameOneColInfor("PIO机笼接口", "数量", lpFileName);
                lk_Read_SameOneColInfor("LEU切换单元状态", "数量", lpFileName);
                lk_Read_SameOneColInfor(@"CTC/TSRS初始化", "数量", lpFileName);
                lk_Read_SameOneColInfor("TCC机柜CAN通信", "数量", lpFileName);
                lk_Read_SameOneColInfor("TCC与联锁通道", "数量", lpFileName);
                lk_Read_SameOneColInfor("TCC与TSRS通道", "数量", lpFileName);
                lk_Read_SameOneColInfor("TCC与车站通道", "数量", lpFileName);
                lk_Read_SameOneColInfor("TCC与联锁机系", "数量", lpFileName);
                lk_Read_SameOneColInfor("TCC与TSRS机系", "数量", lpFileName);
                lk_Read_SameOneColInfor("TCC与车站机系", "数量", lpFileName);
                lk_Read_SameOneColInfor("TCC与CIGS板", "数量", lpFileName);
                lk_Read_SameOneColInfor("LEU通道", "数量", lpFileName);
                lk_Read_SameOneColInfor("LEU端口", "数量", lpFileName);
                lk_Read_SameOneColInfor("区间信号机名称", "总路数", lpFileName);
                lk_Read_SameOneColInfor("区间线路名称", "总路数", lpFileName);
                lk_Read_SameOneColInfor("列控邻站名称", "总路数", lpFileName);
                lk_Read_SameOneColInfor("PIO驱动继电器名称", "总路数", lpFileName);
                lk_Read_SameOneColInfor("PIO采集继电器名称", "总路数", lpFileName);
                lk_Read_SameOneColInfor("灾害继电器名称", "总路数", lpFileName);
                lk_Read_SameOneColInfor("状态信息轨道名称", "总路数", lpFileName);
                lk_Read_LianSuoRouteInfo(lpFileName); 
            }
        }
        #endregion

        public void Read_Digit_INI(string lpFileName)
        {
            if (lpFileName != null)
            {
                string SecName = "开关量";
                string KeyName = "总路数";
                int t = (int)GetPrivateProfileInt(SecName, KeyName, 0, lpFileName);

                for (int i = 1; i <= t; i++)
                {
                    KeyName = i.ToString();
                    byte[] retVal = new byte[1024];
                    int retlen = GetPrivateProfileString(SecName, KeyName, null, retVal, 1024, lpFileName);
                    string sLine = System.Text.Encoding.Default.GetString(retVal,0,retlen).Trim();
                    string[] sp = new string[256];
                    sp = sLine.Split(',');
                    kglstuct_Struct KGL = new kglstuct_Struct();
                    KGL.Name = sp[0].Trim();
                    KGL.ADNumber = int.Parse(sp[1].Trim());
                    KGL.Type = int.Parse(sp[2].Trim());
                    KGL.ReverseFlag = int.Parse(sp[3].Trim());
                    KGL.FeiJiNo = int.Parse(sp[4].Trim());
                    int len = sp.Length;
                    if (len >= 6)
                    {
                        KGL.SourceFlag = sp[5].Replace('\0', ' ').Trim();
                    }
                    else KGL.SourceFlag = "未配置";
                    c_Device.KGL_Config.Add(KGL);
                }

                SecName = "信号非正常关闭";
                KeyName = "总路数";
                t = (int)GetPrivateProfileInt(SecName, KeyName, 0, lpFileName);
                for (int i = 1; i <= t; i++)
                {
                    KeyName = i.ToString();
                    byte[] retVal = new byte[1024];
                    int retlen = GetPrivateProfileString(SecName, KeyName, null, retVal, 1024, lpFileName);
                    string sLine = System.Text.Encoding.Default.GetString(retVal,0,retlen).Trim();
                    string[] sp = new string[256];
                    sp = sLine.Split(',');
                    objXHJAbnormalShut_Struct xhjAbormal = new objXHJAbnormalShut_Struct();
                    xhjAbormal.LCXhjName = sp[0].Trim();
                    xhjAbormal.XhjNo = int.Parse(sp[1].Trim());
                    xhjAbormal.FrontFirstName = sp[2].Trim();
                    xhjAbormal.FrontFirstCode = int.Parse(sp[3].Trim());
                    xhjAbormal.BackFirstName = sp[4].Trim();
                    xhjAbormal.BackFirstCode = int.Parse(sp[5].Trim());
                    xhjAbormal.CancelButtonName = sp[6].Trim();
                    xhjAbormal.CancelCode = int.Parse(sp[7].Trim());
                    xhjAbormal.LockButtonName = sp[8].Trim();
                    xhjAbormal.LockCode = int.Parse(sp[9].Trim());
                    c_Device.XHJAbnormalShut.Add(xhjAbormal);
                }
            }
        }

        public void Read_MsgGather_INI(string lpFileName)
        {
            if (lpFileName != null)
            {
                string SecName = "设备类型";
                string KeyName = "总数";
                int devTypeNum = (int)GetPrivateProfileInt(SecName, KeyName, 0, lpFileName);
                List<string> tmpDevTypeList = new List<string>();
                for (int i = 1; i <= devTypeNum; i++)
                {
                    KeyName = i.ToString();
                    byte[] retVal = new byte[256];
                    int mm = GetPrivateProfileString(SecName, KeyName, null, retVal, 256, lpFileName);
                    if (mm > 0)
                    {
                        string tmp = System.Text.Encoding.Default.GetString(retVal,0,mm).Trim();
                        tmp = replaceBlank(tmp);
                        tmp = tmp.Trim('\t');
                        if (!c_Device.CheckMsgDevTypeIsValid(tmp))
                        {
                            MessageBox.Show(string.Format("MsgGather.ini 字段:{0} 第{1}行配置错误", SecName, KeyName));
                            return;
                        }                        
                        tmpDevTypeList.Add(tmp);
                        if (c_Device.MsgDataBaseTable.ContainsKey(tmp))
                        {
                            MessageBox.Show(string.Format("MsgGather.ini 字段:{0} 第{1}行配置错误,类型名有重复", SecName, KeyName));
                            return;
                        }
                        string TypeName = tmp;
                        if (TypeName == "电源屏") c_Device.MsgDataBaseTable.Add(tmp, "dyp");
                        else if (TypeName.ToUpper() == "UPS") c_Device.MsgDataBaseTable.Add(tmp, "ups");
                        else if (TypeName == "外电网") c_Device.MsgDataBaseTable.Add(tmp, "wdw");
                        else if (TypeName == "站内轨道电路") c_Device.MsgDataBaseTable.Add(tmp, "zngddl");
                        else if (TypeName == "脉冲轨道电路") c_Device.MsgDataBaseTable.Add(tmp, "mcgddl");
                        else if (TypeName == "电码化") c_Device.MsgDataBaseTable.Add(tmp, "dmh");
                        else if (TypeName == "区间轨道电路") c_Device.MsgDataBaseTable.Add(tmp, "qjgddl");
                        else if (TypeName == "转辙机") c_Device.MsgDataBaseTable.Add(tmp, "dctable");
                        else if (TypeName == "信号机") c_Device.MsgDataBaseTable.Add(tmp, "xhj");
                        else if (TypeName == "电缆绝缘") c_Device.MsgDataBaseTable.Add(tmp, "jy$ll$cy");
                        else if (TypeName == "电源漏流") c_Device.MsgDataBaseTable.Add(tmp, "jy$ll$cy");
                        else if (TypeName == "防灾") c_Device.MsgDataBaseTable.Add(tmp, "jzfz");
                        else if (TypeName == "半自动闭塞") c_Device.MsgDataBaseTable.Add(tmp, "highfreanalog");
                        else if (TypeName == "站联") c_Device.MsgDataBaseTable.Add(tmp, "zhanlian");
                        else if (TypeName == "计轴") c_Device.MsgDataBaseTable.Add(tmp, "jzfz");
                        else if (TypeName == "区间监测") c_Device.MsgDataBaseTable.Add(tmp, "qjjc");                        
                    }
                }
                for (int i = 0; i < tmpDevTypeList.Count; i++)
                {
                    string DicKey = tmpDevTypeList[i];
                    objMsgGatherStruct tmpMsgGather = new objMsgGatherStruct();
                    
                    SecName = tmpDevTypeList[i] + "属性";
                    KeyName = "总数";
                    int tmpAttriNum = (int)GetPrivateProfileInt(SecName, KeyName, 0, lpFileName);
                    for (int k = 1; k <= tmpAttriNum; k++)
                    {
                        KeyName = k.ToString();
                        byte[] retVal = new byte[1024];
                        int mm = GetPrivateProfileString(SecName, KeyName, null, retVal, 1024, lpFileName);
                        if (mm > 0)
                        {
                            string sLine = System.Text.Encoding.Default.GetString(retVal,0,mm).Trim();
                            string[] sp = new string[256];
                            sp = sLine.Split(',','，');
                            objMsgAttriStruct tmpAttri = new objMsgAttriStruct();
                            if (sp.Length > 4 || sp.Length == 0)
                            {
                                MessageBox.Show(string.Format("MsgGather.ini 字段:{0} 第{1}行配置错误", SecName, KeyName));
                                return;
                            }
                            string tmpString = sp[0].Trim();
                            tmpString.Trim();
                            tmpString.Trim('\t');                            
                            tmpAttri.AttriName = tmpString;
                            if (sp.Length >= 2)     //有配置 单位
                            {
                                tmpString = sp[1].Trim();
                                tmpString.Trim();
                                tmpString.Trim('\t');
                                tmpAttri.UnitName = tmpString;
                            }
                            else tmpAttri.UnitName = "";
                            if (sp.Length >= 3)     //有配置模拟量类型
                            {
                                string hexsting = sp[2].Trim();     //得到的是表示16进制的字符串
                                if (hexsting == "")
                                {
                                    tmpAttri.AnalogType = AnalogCodeType.None;
                                }
                                else
                                {
                                    int k1 = ConvertHexStringToInt(hexsting);
                                    if (k1 == -1)
                                    {
                                        MessageBox.Show(string.Format("MsgGather.ini 字段:{0} 第{1}行类型配置错误", SecName, KeyName));
                                        return;
                                    }
                                    else
                                    {
                                        if (c_Device.CheckMsgDevTypeIncludAnalogType(DicKey, k1))
                                        {
                                            tmpAttri.AnalogType = (AnalogCodeType)k1;
                                        }
                                        else MessageBox.Show(string.Format("MsgGather.ini 字段:{0} 第{1}行类型配置错误", SecName, KeyName));
                                    }
                                }
                            }
                            else tmpAttri.AnalogType = AnalogCodeType.None;
                            tmpMsgGather.ArrtiList.Add(tmpAttri);
                        }
                    }
                    
                    SecName = tmpDevTypeList[i] + "路数";
                    KeyName = "总数";
                    int tmpDevNum = (int)GetPrivateProfileInt(SecName, KeyName, 0, lpFileName);
                    for (int k = 1; k <= tmpDevNum;k++ )
                    {
                        KeyName = k.ToString();
                        byte[] retVal = new byte[256];
                        int mm = GetPrivateProfileString(SecName, KeyName, null, retVal, 256, lpFileName);
                        if (mm > 0)
                        {
                            string sLine = System.Text.Encoding.Default.GetString(retVal,0,mm).Trim();
                            string[] sp = new string[256];
                            sp = sLine.Split(',','，');
                            objMsgDevStruct tmpMsgDev = new objMsgDevStruct();
                            tmpMsgDev.DevName = sp[0].Trim();
                            if ((sp.Length-1) != tmpMsgGather.ArrtiList.Count)
                            {
                                MessageBox.Show(string.Format("MsgGather.ini 字段:{0} 第{1}行配置错误,跟属性个数不匹配", SecName, KeyName));
                                return;
                            }
                            for (int m = 0; m < (sp.Length - 1); m++)
                            {
                                string tmp = sp[m + 1].Trim();
                                try
                                {
                                    if (c_Device.CheckDevCfgAnalogNumIsValie(DicKey, tmpMsgGather.ArrtiList[m].AnalogType, int.Parse(tmp)))
                                    {
                                        tmpMsgDev.AnalogSet.Add(int.Parse(tmp));
                                    }
                                    else
                                    {
                                        MessageBox.Show(string.Format("MsgGather.ini 字段:{0} 第{1}行配置,设备名:{2},第{3}个属性配置越界", SecName, KeyName,tmpMsgDev.DevName,m+1));
                                        return;
                                    }
                                }
                                catch (Exception e)
                                {
                                    MessageBox.Show(string.Format("MsgGather.ini 字段:{0} 第{1}行配置错误", SecName, KeyName));
                                    return;
                                }
                            }
                            tmpMsgGather.DevList.Add(tmpMsgDev);
                        }
                    }
                    SecName = tmpDevTypeList[i] + "菜单";
                    KeyName = "总数";
                    int tmpMenuNum = (int)GetPrivateProfileInt(SecName, KeyName, 0, lpFileName);
                    if (tmpMenuNum > 0)
                    {
                        for (int k = 1; k <= tmpMenuNum; k++)
                        {
                            KeyName = k.ToString();
                            byte[] retVal = new byte[256];
                            int mm = GetPrivateProfileString(SecName, KeyName, null, retVal, 256, lpFileName);
                            if (mm > 0)
                            {
                                string sLine = System.Text.Encoding.Default.GetString(retVal, 0, mm).Trim();
                                string[] sp = new string[256];
                                sp = sLine.Split(',', '，');
                                if (sp.Length != 2)
                                {
                                    MessageBox.Show(string.Format("MsgGather.ini 字段:{0} 第{1}行配置错误", SecName, KeyName));
                                    return;
                                }
                                objMsgMenuStruct tmpMsgMenu = new objMsgMenuStruct();
                                string tmpString = sp[0];
                                tmpString.Trim();
                                tmpString.Trim('\0');
                                tmpMsgMenu.MenuName = tmpString;
                                tmpString = sp[1];
                                tmpString.Trim();
                                tmpString.Trim('\0');
                                try
                                {
                                    tmpMsgMenu.MenuID = int.Parse(tmpString);
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine(e);
                                    MessageBox.Show(string.Format("MsgGather.ini 字段:{0} 第{1}行配置错误", SecName, KeyName));
                                    return;
                                }
                                tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            }
                        }
                    }
                    else    //没有配置菜单项，采用默认配置                
                    {
                        string TypeName = tmpDevTypeList[i];
                        
                        if (TypeName == "电源屏")
                        {
                            objMsgMenuStruct tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "日报表";
                            tmpMsgMenu.MenuID = 101;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "实时曲线";
                            tmpMsgMenu.MenuID = 102;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "日曲线";
                            tmpMsgMenu.MenuID = 103;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "月曲线";
                            tmpMsgMenu.MenuID = 104;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "年曲线";
                            tmpMsgMenu.MenuID = 105;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                        }
                        else if (TypeName.ToUpper() == "UPS")
                        {
                            objMsgMenuStruct tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "日报表";
                            tmpMsgMenu.MenuID = 201;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "实时曲线";
                            tmpMsgMenu.MenuID = 202;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "日曲线";
                            tmpMsgMenu.MenuID = 203;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "月曲线";
                            tmpMsgMenu.MenuID = 204;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "年曲线";
                            tmpMsgMenu.MenuID = 205;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                        }
                        else if (TypeName == "外电网")
                        {
                            objMsgMenuStruct tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "日报表";
                            tmpMsgMenu.MenuID = 301;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "实时曲线";
                            tmpMsgMenu.MenuID = 302;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "日曲线";
                            tmpMsgMenu.MenuID = 303;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "月曲线";
                            tmpMsgMenu.MenuID = 304;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "年曲线";
                            tmpMsgMenu.MenuID = 305;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu.MenuName = "故障曲线";
                            tmpMsgMenu.MenuID = 306;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                        }
                        else if (TypeName == "站内轨道电路")
                        {
                            objMsgMenuStruct tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "日报表";
                            tmpMsgMenu.MenuID = 401;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "实时曲线";
                            tmpMsgMenu.MenuID = 402;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "日曲线";
                            tmpMsgMenu.MenuID = 403;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "月曲线";
                            tmpMsgMenu.MenuID = 404;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "年曲线";
                            tmpMsgMenu.MenuID = 405;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);                            
                        }
                        else if (TypeName == "脉冲轨道电路")
                        {
                            objMsgMenuStruct tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "日报表";
                            tmpMsgMenu.MenuID = 501;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "实时曲线";
                            tmpMsgMenu.MenuID = 502;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "日曲线";
                            tmpMsgMenu.MenuID = 503;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "月曲线";
                            tmpMsgMenu.MenuID = 504;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "年曲线";
                            tmpMsgMenu.MenuID = 505;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu.MenuName = "高压不对称曲线";
                            tmpMsgMenu.MenuID = 506;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                        }
                        else if (TypeName == "电码化")
                        {
                            objMsgMenuStruct tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "日报表";
                            tmpMsgMenu.MenuID = 601;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "实时曲线";
                            tmpMsgMenu.MenuID = 602;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "日曲线";
                            tmpMsgMenu.MenuID = 603;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "月曲线";
                            tmpMsgMenu.MenuID = 604;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "年曲线";
                            tmpMsgMenu.MenuID =605;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);  
                        }
                        else if (TypeName == "区间轨道电路")
                        {
                            objMsgMenuStruct tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "日报表";
                            tmpMsgMenu.MenuID = 701;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "实时曲线";
                            tmpMsgMenu.MenuID = 702;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "日曲线";
                            tmpMsgMenu.MenuID = 703;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "月曲线";
                            tmpMsgMenu.MenuID = 704;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "年曲线";
                            tmpMsgMenu.MenuID = 705;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);  
                        }
                        else if (TypeName == "转辙机")
                        {
                            objMsgMenuStruct tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "日报表";
                            tmpMsgMenu.MenuID = 801;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "实时曲线";
                            tmpMsgMenu.MenuID = 802;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "日曲线";
                            tmpMsgMenu.MenuID = 803;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "月曲线";
                            tmpMsgMenu.MenuID = 804;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "年曲线";
                            tmpMsgMenu.MenuID = 805;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu.MenuName = "道岔动作电流曲线";
                            tmpMsgMenu.MenuID = 806;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu.MenuName = "道岔动作功率曲线";
                            tmpMsgMenu.MenuID = 807;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu); 
                        }
                        else if (TypeName == "信号机")
                        {
                            objMsgMenuStruct tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "实时曲线";
                            tmpMsgMenu.MenuID = 901;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "日曲线";
                            tmpMsgMenu.MenuID = 902;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "月曲线";
                            tmpMsgMenu.MenuID = 903;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                        }
                        else if (TypeName == "电缆绝缘")
                        {
                            objMsgMenuStruct tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "日报表";
                            tmpMsgMenu.MenuID = 1001;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);                            
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "月曲线";
                            tmpMsgMenu.MenuID = 1002;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "年曲线";
                            tmpMsgMenu.MenuID = 1003;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                        }
                        else if (TypeName == "电源漏流")
                        {
                            objMsgMenuStruct tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "日报表";
                            tmpMsgMenu.MenuID = 1101;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "月曲线";
                            tmpMsgMenu.MenuID = 1102;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "年曲线";
                            tmpMsgMenu.MenuID = 1103;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                        }
                        else if (TypeName == "防灾")
                        {
                            objMsgMenuStruct tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "日报表";
                            tmpMsgMenu.MenuID = 1201;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "实时曲线";
                            tmpMsgMenu.MenuID = 1202;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "日曲线";
                            tmpMsgMenu.MenuID = 1203;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "月曲线";
                            tmpMsgMenu.MenuID = 1204;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "年曲线";
                            tmpMsgMenu.MenuID = 1205;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);  
                        }
                        else if (TypeName == "半自动闭塞")
                        {
                            objMsgMenuStruct tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "日报表";
                            tmpMsgMenu.MenuID = 1301;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "实时曲线";
                            tmpMsgMenu.MenuID = 1302;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "日曲线";
                            tmpMsgMenu.MenuID = 1303;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "月曲线";
                            tmpMsgMenu.MenuID = 1304;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "年曲线";
                            tmpMsgMenu.MenuID = 1305;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);  
                        }
                        else if (TypeName == "站联")
                        {
                            objMsgMenuStruct tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "日报表";
                            tmpMsgMenu.MenuID = 1401;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "实时曲线";
                            tmpMsgMenu.MenuID = 1402;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "日曲线";
                            tmpMsgMenu.MenuID = 1403;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "月曲线";
                            tmpMsgMenu.MenuID = 1404;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "年曲线";
                            tmpMsgMenu.MenuID = 1405;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);  
                        }
                        else if (TypeName == "计轴")
                        {
                            objMsgMenuStruct tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "日报表";
                            tmpMsgMenu.MenuID = 1501;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "实时曲线";
                            tmpMsgMenu.MenuID = 1502;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "日曲线";
                            tmpMsgMenu.MenuID = 1503;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "月曲线";
                            tmpMsgMenu.MenuID = 1504;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "年曲线";
                            tmpMsgMenu.MenuID = 1505;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);  
                        }
                        else if (TypeName == "区间监测")
                        {
                            objMsgMenuStruct tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "日报表";
                            tmpMsgMenu.MenuID = 1601;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "实时曲线";
                            tmpMsgMenu.MenuID = 1602;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "日曲线";
                            tmpMsgMenu.MenuID = 1603;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "月曲线";
                            tmpMsgMenu.MenuID = 1604;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);
                            tmpMsgMenu = new objMsgMenuStruct();
                            tmpMsgMenu.MenuName = "年曲线";
                            tmpMsgMenu.MenuID = 1605;
                            tmpMsgGather.MenuList.Add(tmpMsgMenu);  
                        }
                    }
                    c_Device.DeviceMsgGather.Add(DicKey, tmpMsgGather);
                }
            }
        }

        public void ReadSysConfig_INI()
        {
            string FilePath = System.Environment.CurrentDirectory;
            string cfgFilePath = FilePath + "\\CFG\\";
            string sysCfgFilePath = cfgFilePath + "SysCfg.ini";
            if (sysCfgFilePath != null)
            {
                string SecName = "本机";
                string KeyName = "类型";
                byte[] retVal = new byte[1024];
                int mm = GetPrivateProfileString(SecName, KeyName, null, retVal, 1024, sysCfgFilePath);
                if (mm > 0)
                {
                    string s = System.Text.Encoding.Default.GetString(retVal, 0, mm).Trim('\0');
                    if (s == "站机") c_Config.sysConfig.TerminalFlag = 0;
                    else if (s == "终端") c_Config.sysConfig.TerminalFlag = 1;
                }
                 KeyName = "电报码";
                 retVal.Initialize();
                mm = GetPrivateProfileString(SecName, KeyName, null, retVal, 1024, sysCfgFilePath);
                if (mm ==3 )
                {
                    Array.Copy(retVal,0,c_Config.sysConfig.TelexCodeB,0,3);
                    c_Config.sysConfig.TelexCode = System.Text.Encoding.Default.GetString(retVal, 0, mm).Trim();                    
                }
                KeyName = "服务器电报码";
                retVal.Initialize();
                mm = GetPrivateProfileString(SecName, KeyName, null, retVal, 1024, sysCfgFilePath);
                if (mm == 3)
                {
                    Array.Copy(retVal, 0, c_Config.sysConfig.SevTelexCodeB, 0, 3);
                    c_Config.sysConfig.SevTelexCode = System.Text.Encoding.Default.GetString(retVal, 0, mm).Trim();
                }
                KeyName = "服务器IP地址";
                retVal.Initialize();
                mm = GetPrivateProfileString(SecName, KeyName, null, retVal, 1024, sysCfgFilePath);
                if (mm !=0)
                {
                    c_Config.sysConfig.SevIpAddress = System.Text.Encoding.Default.GetString(retVal, 0, mm).Trim();
                }
                KeyName = "服务器端口号";
                retVal.Initialize();
                c_Config.sysConfig.SevPort = (int)GetPrivateProfileInt(SecName, KeyName, 0, sysCfgFilePath);                
            }
        }

        public void ReadOther_INI(string lpFileName)
        {
            List<string> lev1list = new List<string>();
            List<string> lev2list = new List<string>();
            List<string> lev3list = new List<string>();
            List<string> levyjlist = new List<string>();
            lev1list.Add("挤岔报警");
            lev1list.Add("列车信号非正常关闭报警");
            lev1list.Add("故障通知按钮报警");
            lev1list.Add("火灾报警");
            lev1list.Add("防灾异物侵限报警");
            lev1list.Add("SJ锁闭封连报警");

            lev2list.Add(@"外电网输入电源断相/断电报警");
            lev2list.Add("外电网三相电源错序报警");
            lev2list.Add("外电网输入电源瞬间断电报警");
            lev2list.Add("电源屏输出断电报警");
            lev2list.Add("列车信号主灯丝断丝报警");
            lev2list.Add("熔丝断丝报警");
            lev2list.Add("转辙机表示缺口报警");
            lev2list.Add("环境监测报警");
            lev2list.Add("计算机联锁系统报警");
            lev2list.Add("列控系统报警");
            lev2list.Add("ZPW-2000系统报警");
            lev2list.Add("TDCS/CTC系统报警");
            lev2list.Add("道岔无表示报警");
            lev2list.Add("智能电源屏报警");
            lev2list.Add("TSRS设备报警");
            lev2list.Add("RBC报警");
            lev2list.Add("控制台按钮操作记录");

            lev3list.Add("电气特性超限报警");
            lev3list.Add("轨道长期占用报警");
            lev3list.Add("监测与其他系统通信接口故障报警");
            lev3list.Add("微机监测内部采集通信故障报警");


            levyjlist.Add("各种设备模拟量变化趋势、突变、异常波动预警");
            levyjlist.Add("道岔运用次数超限预警");
            levyjlist.Add("补偿电容断线预警");
            levyjlist.Add("智能分析预警");
            levyjlist.Add("智能分析故障诊断");

            if (lpFileName != null)
            {
                string SecName = "报警配置";
                string KeyName = "SJ锁闭封连报警";
                if (GetPrivateProfileInt(SecName, KeyName, 0xff, lpFileName) == 1)
                {
                    lev1list.Remove(KeyName);
                    lev2list.Remove(KeyName);
                    lev3list.Remove(KeyName);
                    levyjlist.Remove(KeyName);
                }
                KeyName = "道岔表示不一致";
                if (GetPrivateProfileInt(SecName, KeyName, 0xff, lpFileName) == 1)
                {
                    lev1list.Remove(KeyName);
                    lev2list.Remove(KeyName);
                    lev3list.Remove(KeyName);
                    levyjlist.Remove(KeyName);
                }
                KeyName = "挤岔";
                if (GetPrivateProfileInt(SecName, KeyName, 0xff, lpFileName) == 1)
                {
                    lev1list.Remove(KeyName);
                    lev2list.Remove(KeyName);
                    lev3list.Remove(KeyName);
                    levyjlist.Remove(KeyName);
                }
                KeyName = "列车信号非正常关闭";
                if (GetPrivateProfileInt(SecName, KeyName, 0xff, lpFileName) == 1)
                {
                    lev1list.Remove(KeyName);
                    lev2list.Remove(KeyName);
                    lev3list.Remove(KeyName);
                    levyjlist.Remove(KeyName);
                }
                KeyName = "火灾";
                if (GetPrivateProfileInt(SecName, KeyName, 0xff, lpFileName) == 1)
                {
                    lev1list.Remove(KeyName);
                    lev2list.Remove(KeyName);
                    lev3list.Remove(KeyName);
                    levyjlist.Remove(KeyName);
                }
                KeyName = "故障通知按钮";
                if (GetPrivateProfileInt(SecName, KeyName, 0xff, lpFileName) == 1)
                {
                    lev1list.Remove(KeyName);
                    lev2list.Remove(KeyName);
                    lev3list.Remove(KeyName);
                    levyjlist.Remove(KeyName);
                }
                KeyName = @"外电网输入电源断相/断电报警";
                if (GetPrivateProfileInt(SecName, KeyName, 0xff, lpFileName) == 1)
                {
                    lev1list.Remove(KeyName);
                    lev2list.Remove(KeyName);
                    lev3list.Remove(KeyName);
                    levyjlist.Remove(KeyName);
                }
                KeyName = "外电网三相电源错序报警";
                if (GetPrivateProfileInt(SecName, KeyName, 0xff, lpFileName) == 1)
                {
                    lev1list.Remove(KeyName);
                    lev2list.Remove(KeyName);
                    lev3list.Remove(KeyName);
                    levyjlist.Remove(KeyName);
                }
                KeyName = "外电网输入电源瞬间断电报警";
                if (GetPrivateProfileInt(SecName, KeyName, 0xff, lpFileName) == 1)
                {
                    lev1list.Remove(KeyName);
                    lev2list.Remove(KeyName);
                    lev3list.Remove(KeyName);
                    levyjlist.Remove(KeyName);
                }
                KeyName = "列车信号主灯丝断丝报警";
                if (GetPrivateProfileInt(SecName, KeyName, 0xff, lpFileName) == 1)
                {
                    lev1list.Remove(KeyName);
                    lev2list.Remove(KeyName);
                    lev3list.Remove(KeyName);
                    levyjlist.Remove(KeyName);
                }
                KeyName = "熔丝断丝报警";
                if (GetPrivateProfileInt(SecName, KeyName, 0xff, lpFileName) == 1)
                {
                    lev1list.Remove(KeyName);
                    lev2list.Remove(KeyName);
                    lev3list.Remove(KeyName);
                    levyjlist.Remove(KeyName);
                }
                KeyName = "转辙机表示缺口报警";
                if (GetPrivateProfileInt(SecName, KeyName, 0xff, lpFileName) == 1)
                {
                    lev1list.Remove(KeyName);
                    lev2list.Remove(KeyName);
                    lev3list.Remove(KeyName);
                    levyjlist.Remove(KeyName);
                }
                KeyName = "区间设备报警";
                if (GetPrivateProfileInt(SecName, KeyName, 0xff, lpFileName) == 1)
                {
                    lev1list.Remove(KeyName);
                    lev2list.Remove(KeyName);
                    lev3list.Remove(KeyName);
                    levyjlist.Remove(KeyName);
                }
                KeyName = "微机监测内部采集通信故障报警";
                if (GetPrivateProfileInt(SecName, KeyName, 0xff, lpFileName) == 1)
                {
                    lev1list.Remove(KeyName);
                    lev2list.Remove(KeyName);
                    lev3list.Remove(KeyName);
                    levyjlist.Remove(KeyName);
                }
                KeyName = "环境监测报警";
                if (GetPrivateProfileInt(SecName, KeyName, 0xff, lpFileName) == 1)
                {
                    lev1list.Remove(KeyName);
                    lev2list.Remove(KeyName);
                    lev3list.Remove(KeyName);
                    levyjlist.Remove(KeyName);
                }
                KeyName = "TDCS/CTC系统报警";
                if (GetPrivateProfileInt(SecName, KeyName, 0xff, lpFileName) == 1)
                {
                    lev1list.Remove(KeyName);
                    lev2list.Remove(KeyName);
                    lev3list.Remove(KeyName);
                    levyjlist.Remove(KeyName);
                }
                KeyName = "列控系统报警";
                if (GetPrivateProfileInt(SecName, KeyName, 0xff, lpFileName) == 1)
                {
                    lev1list.Remove(KeyName);
                    lev2list.Remove(KeyName);
                    lev3list.Remove(KeyName);
                    levyjlist.Remove(KeyName);
                }       
                KeyName = "计算机联锁系统报警";
                if (GetPrivateProfileInt(SecName, KeyName, 0xff, lpFileName) == 1)
                {
                    lev1list.Remove(KeyName);
                    lev2list.Remove(KeyName);
                    lev3list.Remove(KeyName);
                    levyjlist.Remove(KeyName);
                }
                KeyName = "电气特性超限报警";
                if (GetPrivateProfileInt(SecName, KeyName, 0xff, lpFileName) == 1)
                {
                    lev1list.Remove(KeyName);
                    lev2list.Remove(KeyName);
                    lev3list.Remove(KeyName);
                    levyjlist.Remove(KeyName);
                }
                KeyName = "监测与其他系统通信接口故障报警";
                if (GetPrivateProfileInt(SecName, KeyName, 0xff, lpFileName) == 1)
                {
                    lev1list.Remove(KeyName);
                    lev2list.Remove(KeyName);
                    lev3list.Remove(KeyName);
                    levyjlist.Remove(KeyName);
                }
                KeyName = "道岔运用次数超限预警";
                if (GetPrivateProfileInt(SecName, KeyName, 0xff, lpFileName) == 1)
                {
                    lev1list.Remove(KeyName);
                    lev2list.Remove(KeyName);
                    lev3list.Remove(KeyName);
                    levyjlist.Remove(KeyName);
                }
                KeyName = "补偿电容断线预警";
                if (GetPrivateProfileInt(SecName, KeyName, 0xff, lpFileName) == 1)
                {
                    lev1list.Remove(KeyName);
                    lev2list.Remove(KeyName);
                    lev3list.Remove(KeyName);
                    levyjlist.Remove(KeyName);
                }
                KeyName = @"ZPW-2000系统报警";
                if (GetPrivateProfileInt(SecName, KeyName, 0xff, lpFileName) == 1)
                {
                    lev1list.Remove(KeyName);
                    lev2list.Remove(KeyName);
                    lev3list.Remove(KeyName);
                    levyjlist.Remove(KeyName);
                }
                KeyName = "应答器报警";
                if (GetPrivateProfileInt(SecName, KeyName, 0xff, lpFileName) == 1)
                {
                    lev1list.Remove(KeyName);
                    lev2list.Remove(KeyName);
                    lev3list.Remove(KeyName);
                    levyjlist.Remove(KeyName);
                }
                KeyName = "智能电源屏报警";
                if (GetPrivateProfileInt(SecName, KeyName, 0xff, lpFileName) == 1)
                {
                    lev1list.Remove(KeyName);
                    lev2list.Remove(KeyName);
                    lev3list.Remove(KeyName);
                    levyjlist.Remove(KeyName);
                }
                KeyName = "防灾异物侵限报警";
                if (GetPrivateProfileInt(SecName, KeyName, 0xff, lpFileName) == 1)
                {
                    lev1list.Remove(KeyName);
                    lev2list.Remove(KeyName);
                    lev3list.Remove(KeyName);
                    levyjlist.Remove(KeyName);
                }
                KeyName = "TSRS设备报警";
                if (GetPrivateProfileInt(SecName, KeyName, 0xff, lpFileName) == 1)
                {
                    lev1list.Remove(KeyName);
                    lev2list.Remove(KeyName);
                    lev3list.Remove(KeyName);
                    levyjlist.Remove(KeyName);
                }
                KeyName = "RBC报警";
                if (GetPrivateProfileInt(SecName, KeyName, 0xff, lpFileName) == 1)
                {
                    lev1list.Remove(KeyName);
                    lev2list.Remove(KeyName);
                    lev3list.Remove(KeyName);
                    levyjlist.Remove(KeyName);
                }
                KeyName = "电源屏输出断电报警";
                if (GetPrivateProfileInt(SecName, KeyName, 0xff, lpFileName) == 1)
                {
                    lev1list.Remove(KeyName);
                    lev2list.Remove(KeyName);
                    lev3list.Remove(KeyName);
                    levyjlist.Remove(KeyName);
                }
                KeyName = "道岔无表示报警";
                if (GetPrivateProfileInt(SecName, KeyName, 0xff, lpFileName) == 1)
                {
                    lev1list.Remove(KeyName);
                    lev2list.Remove(KeyName);
                    lev3list.Remove(KeyName);
                    levyjlist.Remove(KeyName);
                }
                KeyName = @"各种设备模拟量变化趋势、突变、异常波动预警";
                if (GetPrivateProfileInt(SecName, KeyName, 0xff, lpFileName) == 1)
                {
                    lev1list.Remove(KeyName);
                    lev2list.Remove(KeyName);
                    lev3list.Remove(KeyName);
                    levyjlist.Remove(KeyName);
                }
                KeyName = @"控制台按钮操作记录";
                if (GetPrivateProfileInt(SecName, KeyName, 0xff, lpFileName) == 1)
                {
                    lev1list.Remove(KeyName);
                    lev2list.Remove(KeyName);
                    lev3list.Remove(KeyName);
                    levyjlist.Remove(KeyName);
                }
                KeyName = "轨道长期占用报警";
                if (GetPrivateProfileInt(SecName, KeyName, 0xff, lpFileName) == 1)
                {
                    lev1list.Remove(KeyName);
                    lev2list.Remove(KeyName);
                    lev3list.Remove(KeyName);
                    levyjlist.Remove(KeyName);
                }
                KeyName = "智能分析预警";
                if (GetPrivateProfileInt(SecName, KeyName, 0xff, lpFileName) == 1)
                {
                    lev1list.Remove(KeyName);
                    lev2list.Remove(KeyName);
                    lev3list.Remove(KeyName);
                    levyjlist.Remove(KeyName);
                }
                KeyName = "智能分析故障诊断";
                if (GetPrivateProfileInt(SecName, KeyName, 0xff, lpFileName) == 1)
                {
                    lev1list.Remove(KeyName);
                    lev2list.Remove(KeyName);
                    lev3list.Remove(KeyName);
                    levyjlist.Remove(KeyName);
                }
            }
            c_Device.Alarm_ConfigList.Add(1, lev1list);
            c_Device.Alarm_ConfigList.Add(2, lev2list);
            c_Device.Alarm_ConfigList.Add(3, lev3list);
            c_Device.Alarm_ConfigList.Add(4, levyjlist);
        }

        public void ReadDCQK_INI(string lpFileName)
        {
            if (lpFileName != "")
            {
                string SecName = "模拟量项目";
                string KeyName = "子项数目";
                uint analogTypeNum = 0;
                analogTypeNum = GetPrivateProfileInt(SecName, KeyName, 0, lpFileName);
                for (int i = 1; i <= analogTypeNum; i++)
                {
                    string s_SecName = "子项" + i.ToString();
                    string s_KeyName = "名称";
                    byte[] retVal = new byte[255];
                    int retlen = GetPrivateProfileString(s_SecName, s_KeyName, null, retVal, 255, lpFileName);
                    string sdickey = System.Text.Encoding.Default.GetString(retVal, 0, retlen).Trim('\0');
                    objAnalogTypeStruct TmpAnalogCFG = new objAnalogTypeStruct();
                    if (sdickey == "道岔缺口模拟量")
                    {
                        ReadAnalogList(s_SecName, lpFileName, ref TmpAnalogCFG);
                        c_Device.DCQK_AnlogConfig.Add(sdickey,TmpAnalogCFG);
                    }
                }
            }
        }

        public void ReadHK_INI(string lpFileName)
        {
            if (lpFileName != "")
            {
                string SecName = "模拟量项目";
                string KeyName = "子项数目";
                uint analogTypeNum = 0;
                analogTypeNum = GetPrivateProfileInt(SecName, KeyName, 0, lpFileName);
                for (int i = 1; i <= analogTypeNum; i++)
                {
                    string s_SecName = "子项" + i.ToString();
                    string s_KeyName = "名称";
                    byte[] retVal = new byte[255];
                    int retlen = GetPrivateProfileString(s_SecName, s_KeyName, null, retVal, 255, lpFileName);
                    string sdickey = System.Text.Encoding.Default.GetString(retVal, 0, retlen).Trim('\0');
                    objAnalogTypeStruct TmpAnalogCFG = new objAnalogTypeStruct();
                    if (sdickey == "环境监测" || sdickey == "空调控制")
                    {
                        ReadAnalogList(s_SecName, lpFileName, ref TmpAnalogCFG);
                        c_Device.HK_AnlogConfig.Add(sdickey, TmpAnalogCFG);
                    }
                }
            }
        }
        /// <summary>
        /// 获得INI配置文件路径
        /// </summary>
        /// <returns></returns>
        public string GetINI_FilePath()
        {
            string FilePath = System.Environment.CurrentDirectory;
            string cfgFilePath = FilePath + "\\CFG\\";
            string sysCfgFilePath = cfgFilePath + "SysCfg.ini";
            if (sysCfgFilePath != null)
            {
                string SecName = "本机";
                string KeyName = "电报码";
                byte[] retVal = new byte[1024];
                int mm = GetPrivateProfileString(SecName, KeyName, null, retVal, 1024, sysCfgFilePath);
                if (mm > 0)
                {
                    string tmpDBM = System.Text.Encoding.Default.GetString(retVal,0,mm).Trim('\0');
                    tmpDBM.Trim();
                    string IniCfgFilePath = cfgFilePath + tmpDBM;
                    if (!Directory.Exists(IniCfgFilePath))
                    {
                        Directory.CreateDirectory(IniCfgFilePath);
                    }
                    return IniCfgFilePath;
                }
            }
            else
            {
                MessageBox.Show("SysCfg.ini找不到或者格式错误!");
            }
            return "";
        }

        public void Read_FLBL_INI(string lpFileName)
        {
            if (lpFileName != null)
            {
                string SecName = "分路不良区段描述";
                string KeyName = "总数";
                int flblNum = (int)GetPrivateProfileInt(SecName, KeyName, 0, lpFileName);
                objFLBL_Struct tmpFlbl = new objFLBL_Struct();
                for (int i = 1; i <= flblNum; i++)
                {
                    KeyName = i.ToString();
                    byte[] retVal = new byte[1024];
                    int mm = GetPrivateProfileString(SecName, KeyName, null, retVal, 1024, lpFileName);
                    if (mm > 0)
                    {
                        string slen = System.Text.Encoding.Default.GetString(retVal,0,mm).Trim('\0');
                        slen.Trim();
                        string[] sp = new string[5];
                        sp = slen.Split(',', '，');
                        string tmpString = sp[0];
                        tmpString.Trim();
                        tmpFlbl.SectionName = tmpString;
                        tmpString = sp[1];
                        tmpString.Trim();
                        tmpFlbl.SectionType = byte.Parse(tmpString);
                        tmpString = sp[2];
                        tmpString.Trim();
                        tmpFlbl.FlblType = byte.Parse(tmpString);
                        tmpString = sp[3];
                        tmpString.Trim();
                        tmpFlbl.FlblReason = tmpString;
                        tmpString = sp[4];
                        tmpString.Trim();
                        tmpFlbl.PersonID = Int16.Parse(tmpString);
                        c_Device.FLBL_Config.Add(tmpFlbl);
                    }
                }
            }
        }

        private bool Wirite_FLBL_INI()
        {
            string IniFilePath = GetINI_FilePath();
            if (IniFilePath == "")
            {
            }
            IniFilePath += "\\flbl.ini";
            if (File.Exists(IniFilePath))
            {
                File.Delete(IniFilePath);
            }
            System.IO.StreamWriter sw = new System.IO.StreamWriter(IniFilePath, false, System.Text.Encoding.Default);
            try
            {
                sw.WriteLine("[分路不良区段描述]");
                sw.WriteLine(string.Format("总数 = {0}", c_Device.FLBL_Config.Count));
                sw.Close();
            }
            catch
            {

            }
            string SectionName = "分路不良区段描述";
            for (int i = 1; i <= c_Device.FLBL_Config.Count; i++)
            {
                string keyName = i.ToString();
                StringBuilder valString = new StringBuilder();
                valString.Append(c_Device.FLBL_Config[i - 1].SectionName);
                valString.Append(",");
                valString.Append(c_Device.FLBL_Config[i - 1].SectionType.ToString());
                valString.Append(",");
                valString.Append(c_Device.FLBL_Config[i - 1].FlblType.ToString());
                valString.Append(",");
                valString.Append(c_Device.FLBL_Config[i - 1].FlblReason);
                valString.Append(",");
                valString.Append(c_Device.FLBL_Config[i - 1].PersonID.ToString());
                try
                {
                    WritePrivateProfileString(SectionName, keyName, valString.ToString(), IniFilePath);
                }
                catch
                {
                    Console.WriteLine("写flbl.ini失败");
                    return false;
                }
            }
            return true;
        }

        public bool Modify_FlblSetValue(objFLBL_Struct obj)
        {
            bool NewObj = true;
            for (int i = 0; i < c_Device.FLBL_Config.Count;i++ )
            {
                if (c_Device.FLBL_Config[i].SectionName == obj.SectionName)
                {
                    NewObj = false;
                    c_Device.FLBL_Config[i] = obj;                    
                }
            }
            if (NewObj)
            {
                c_Device.FLBL_Config.Add(obj);                
            }
            if (Wirite_FLBL_INI()) return true;
            else return false;

        }
    }    
}